Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to edition 2024 #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions engine/src/ast/field_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl<'s> Expr<'s> for ComparisonExpr<'s> {
let lhs = self.lhs;

macro_rules! cast_value {
($value:expr, $ty:ident) => {
($value:expr_2021, $ty:ident) => {
match $value {
LhsValue::$ty(value) => value,
_ => unreachable!(),
Expand Down Expand Up @@ -468,7 +468,7 @@ impl<'s> Expr<'s> for ComparisonExpr<'s> {
}),
ComparisonOpExpr::Contains(bytes) => {
macro_rules! search {
($searcher:expr) => {{
($searcher:expr_2021) => {{
let searcher = $searcher;
lhs.compile_with(compiler, false, move |x, _ctx| {
searcher.search_in(cast_value!(x, Bytes).as_ref())
Expand Down
15 changes: 8 additions & 7 deletions engine/src/ast/function_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ impl<'i, 's> LexWith<'i, &FilterParser<'s>> for FunctionCallArgExpr<'s> {

macro_rules! c_is_field {
// characters above F/f in the alphabet mean it can't be a decimal or hex int
($c:expr) => {
($c:expr_2021) => {
(($c.is_ascii_alphanumeric() && !$c.is_ascii_hexdigit()) || $c == '_')
};
}

macro_rules! c_is_field_or_int {
($c:expr) => {
($c:expr_2021) => {
($c.is_ascii_alphanumeric() || $c == '_')
};
}
Expand Down Expand Up @@ -343,11 +343,12 @@ impl<'s> ValueExpr<'s> for FunctionCallExpr<'s> {
}
} else {
CompiledValueExpr::new(move |ctx| {
if let Some(value) = call(&mut args.iter().map(|arg| arg.execute(ctx))) {
debug_assert!(value.get_type() == return_type);
Ok(value)
} else {
Err(return_type)
match call(&mut args.iter().map(|arg| arg.execute(ctx))) {
Some(value) => {
debug_assert!(value.get_type() == return_type);
Ok(value)
}
_ => Err(return_type),
}
})
}
Expand Down
11 changes: 7 additions & 4 deletions engine/src/ast/index_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,13 @@ impl<'s> IndexExpr<'s> {
let call = compiler.compile_function_call_expr(call);
CompiledVecExpr::new(move |ctx| {
let mut iter = MapEachIterator::from_indexes(&indexes[..]);
if let Ok(val) = call.execute(ctx) {
iter.reset(val);
} else {
return TypedArray::default();
match call.execute(ctx) {
Ok(val) => {
iter.reset(val);
}
_ => {
return TypedArray::default();
}
}

TypedArray::from_iter(iter.map(|item| func(&item, ctx)))
Expand Down
2 changes: 1 addition & 1 deletion engine/src/ast/logical_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub enum LogicalExpr<'s> {
impl GetType for LogicalExpr<'_> {
fn get_type(&self) -> Type {
match &self {
LogicalExpr::Combining { ref items, .. } => items[0].get_type(),
LogicalExpr::Combining { items, .. } => items[0].get_type(),
LogicalExpr::Comparison(comparison) => comparison.get_type(),
LogicalExpr::Parenthesized(parenthesized) => parenthesized.expr.get_type(),
LogicalExpr::Unary { arg, .. } => arg.get_type(),
Expand Down
2 changes: 1 addition & 1 deletion engine/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<'a> FunctionParam<'a> {
/// Returns the underlying type if the current parameter is a variable, otherwise an error.
pub fn as_variable(&self) -> Result<&Type, FunctionArgKindMismatchError> {
match self {
Self::Variable(ref ty) => Ok(ty),
Self::Variable(ty) => Ok(ty),
Self::Constant(_) => Err(FunctionArgKindMismatchError {
expected: FunctionArgKind::Field,
actual: FunctionArgKind::Literal,
Expand Down
10 changes: 5 additions & 5 deletions engine/src/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ macro_rules! lex_enum {
// On the parser side, tries to parse either of the given string values,
// and returns the variant if any of them succeeded.
(@decl $preamble:tt $name:ident $input:ident { $($decl:tt)* } { $($expr:tt)* } {
$(#[$meta:meta])* $($s:literal)|+ => $item:ident $(= $value:expr)*,
$(#[$meta:meta])* $($s:literal)|+ => $item:ident $(= $value:expr_2021)*,
$($rest:tt)*
}) => {
lex_enum!(@decl $preamble $name $input {
Expand Down Expand Up @@ -324,27 +324,27 @@ pub fn complete<T>(res: LexResult<'_, T>) -> Result<T, LexError<'_>> {

#[cfg(test)]
macro_rules! assert_ok {
($s:expr, $res:expr, $rest:expr) => {{
($s:expr_2021, $res:expr_2021, $rest:expr_2021) => {{
let expr = $s.unwrap();
assert_eq!(expr, ($res, $rest));
expr.0
}};

($s:expr, $res:expr) => {
($s:expr_2021, $res:expr_2021) => {
assert_ok!($s, $res, "")
};
}

#[cfg(test)]
macro_rules! assert_err {
($s:expr, $kind:expr, $span:expr) => {
($s:expr_2021, $kind:expr_2021, $span:expr_2021) => {
assert_eq!($s, Err(($kind, $span)))
};
}

#[cfg(test)]
macro_rules! assert_json {
($expr:expr, $json:tt) => {{
($expr:expr_2021, $json:tt) => {{
let json = ::serde_json::to_value(&$expr).unwrap();
assert_eq!(json, ::serde_json::json!($json));
json
Expand Down
4 changes: 2 additions & 2 deletions engine/src/rhs_types/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ impl Lex<'_> for IpRange {
}

macro_rules! impl_ip_range_from {
(@single $v:ident, |$input:ident: $ty:ty| $transform:expr) => {
(@single $v:ident, |$input:ident: $ty:ty| $transform:expr_2021) => {
impl From<$ty> for ExplicitIpRange {
fn from($input: $ty) -> Self {
ExplicitIpRange::$v($transform)
}
}
};

($ty:ident { $v4:ty, $v6:ty }, |$input:ident| $transform:expr) => {
($ty:ident { $v4:ty, $v6:ty }, |$input:ident| $transform:expr_2021) => {
impl_ip_range_from!(@single V4, |$input: $v4| $transform);
impl_ip_range_from!(@single V6, |$input: $v6| $transform);

Expand Down
2 changes: 1 addition & 1 deletion engine/src/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ impl<'s> Scheme {
}

/// Iterates over all registered [`lists`](trait.ListDefinition.html).
pub fn lists(&self) -> impl ExactSizeIterator<Item = List<'_>> {
pub fn lists(&self) -> impl ExactSizeIterator<Item = List<'_>> + use<'_> {
(0..self.lists.len()).map(|index| List {
scheme: self,
index,
Expand Down
8 changes: 4 additions & 4 deletions engine/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,12 +768,12 @@ impl<'a> LhsValue<'a> {
/// Both LhsValue::Array and LhsValue::Map support nested elements.
pub fn get(&'a self, item: &FieldIndex) -> Result<Option<&'a LhsValue<'a>>, IndexAccessError> {
match (self, item) {
(LhsValue::Array(arr), FieldIndex::ArrayIndex(ref idx)) => Ok(arr.get(*idx as usize)),
(LhsValue::Array(arr), FieldIndex::ArrayIndex(idx)) => Ok(arr.get(*idx as usize)),
(_, FieldIndex::ArrayIndex(_)) => Err(IndexAccessError {
index: item.clone(),
actual: self.get_type(),
}),
(LhsValue::Map(map), FieldIndex::MapKey(ref key)) => Ok(map.get(key.as_bytes())),
(LhsValue::Map(map), FieldIndex::MapKey(key)) => Ok(map.get(key.as_bytes())),
(_, FieldIndex::MapKey(_)) => Err(IndexAccessError {
index: item.clone(),
actual: self.get_type(),
Expand Down Expand Up @@ -823,7 +823,7 @@ impl<'a> LhsValue<'a> {
let value = value.into();
match item {
FieldIndex::ArrayIndex(idx) => match self {
LhsValue::Array(ref mut arr) => arr
LhsValue::Array(arr) => arr
.insert(idx as usize, value)
.map_err(SetValueError::TypeMismatch),
_ => Err(SetValueError::IndexAccess(IndexAccessError {
Expand All @@ -832,7 +832,7 @@ impl<'a> LhsValue<'a> {
})),
},
FieldIndex::MapKey(name) => match self {
LhsValue::Map(ref mut map) => map
LhsValue::Map(map) => map
.insert(name.as_bytes(), value)
.map_err(SetValueError::TypeMismatch),
_ => Err(SetValueError::IndexAccess(IndexAccessError {
Expand Down
2 changes: 1 addition & 1 deletion ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ indoc.workspace = true
regex.workspace = true

[build-dependencies]
cbindgen = "0.27"
cbindgen = "0.28"

[target.'cfg(unix)'.dev-dependencies]
wirefilter-ffi-ctests = { path = "tests/ctests" }
2 changes: 1 addition & 1 deletion ffi/include/wirefilter.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _WIREFILTER_H_
#define _WIREFILTER_H_

/* Generated with cbindgen:0.27.0 */
/* Generated with cbindgen:0.28.0 */

/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */

Expand Down
Loading
Loading