Skip to content

Commit 6237776

Browse files
committed
Migrate to edition 2024
1 parent fa2fba7 commit 6237776

File tree

33 files changed

+155
-147
lines changed

33 files changed

+155
-147
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ resolver = "2"
1313
authors = [ "Ingvar Stepanyan <[email protected]>" ]
1414
version = "0.7.0"
1515
publish = true
16-
edition = "2021"
16+
edition = "2024"
1717

1818
[workspace.dependencies]
1919
backtrace = "0.3"

engine/benches/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::alloc::System;
55
#[global_allocator]
66
static A: System = System;
77

8-
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
8+
use criterion::{Bencher, Criterion, criterion_group, criterion_main};
99
use std::{borrow::Cow, clone::Clone, fmt::Debug, net::IpAddr};
1010
use wirefilter::{
1111
ExecutionContext, FilterAst, FunctionArgKind, FunctionArgs, GetType, LhsValue, SchemeBuilder,

engine/src/ast/field_expr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
use super::{
2+
Expr,
23
function_expr::FunctionCallExpr,
34
parse::FilterParser,
45
visitor::{Visitor, VisitorMut},
5-
Expr,
66
};
77
use crate::{
8+
Field, List,
89
ast::index_expr::IndexExpr,
910
compiler::Compiler,
1011
filter::CompiledExpr,
11-
lex::{expect, skip_space, span, Lex, LexErrorKind, LexResult, LexWith},
12+
lex::{Lex, LexErrorKind, LexResult, LexWith, expect, skip_space, span},
1213
range_set::RangeSet,
1314
rhs_types::{Bytes, ExplicitIpRange, ListName, Regex, Wildcard},
1415
scheme::Identifier,
1516
searcher::{EmptySearcher, TwoWaySearcher},
1617
strict_partial_ord::StrictPartialOrd,
1718
types::{GetType, LhsValue, RhsValue, RhsValues, Type},
18-
Field, List,
1919
};
2020
use serde::{Serialize, Serializer};
2121
use sliceslice::MemchrSearcher;
@@ -492,7 +492,7 @@ impl Expr for ComparisonExpr {
492492

493493
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
494494
if *USE_AVX2 {
495-
use rand::{thread_rng, Rng};
495+
use rand::{Rng, thread_rng};
496496
use sliceslice::x86::*;
497497

498498
fn slice_to_array<const N: usize>(slice: &[u8]) -> [u8; N] {
@@ -570,7 +570,7 @@ impl Expr for ComparisonExpr {
570570
}
571571
#[cfg(target_arch = "wasm32")]
572572
if *USE_SIMD128 {
573-
use rand::{thread_rng, Rng};
573+
use rand::{Rng, thread_rng};
574574
use sliceslice::wasm32::*;
575575

576576
let position = thread_rng().gen_range(1..bytes.len());
@@ -649,6 +649,7 @@ impl Expr for ComparisonExpr {
649649
mod tests {
650650
use super::*;
651651
use crate::{
652+
BytesFormat, FieldRef, ParserSettings,
652653
ast::{
653654
function_expr::{FunctionCallArgExpr, FunctionCallExpr},
654655
logical_expr::LogicalExpr,
@@ -664,7 +665,6 @@ mod tests {
664665
rhs_types::{IpRange, RegexFormat},
665666
scheme::{FieldIndex, IndexAccessError, Scheme},
666667
types::ExpectedType,
667-
BytesFormat, FieldRef, ParserSettings,
668668
};
669669
use cidr::IpCidr;
670670
use std::sync::LazyLock;

engine/src/ast/function_expr.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use super::{
2+
ValueExpr,
23
parse::FilterParser,
34
visitor::{Visitor, VisitorMut},
4-
ValueExpr,
55
};
66
use crate::{
7+
FunctionRef,
78
ast::{
89
field_expr::{ComparisonExpr, ComparisonOp, ComparisonOpExpr},
910
index_expr::IndexExpr,
@@ -15,11 +16,10 @@ use crate::{
1516
ExactSizeChain, FunctionArgs, FunctionDefinition, FunctionDefinitionContext, FunctionParam,
1617
FunctionParamError,
1718
},
18-
lex::{expect, skip_space, span, Lex, LexError, LexErrorKind, LexResult, LexWith},
19+
lex::{Lex, LexError, LexErrorKind, LexResult, LexWith, expect, skip_space, span},
1920
lhs_types::Array,
2021
scheme::Function,
2122
types::{GetType, LhsValue, RhsValue, Type},
22-
FunctionRef,
2323
};
2424
use serde::Serialize;
2525
use std::hash::{Hash, Hasher};
@@ -280,10 +280,9 @@ impl ValueExpr for FunctionCallExpr {
280280
#[inline(always)]
281281
fn compute<'s, 'a, I: ExactSizeIterator<Item = CompiledValueResult<'a>>>(
282282
first: CompiledValueResult<'a>,
283-
call: &(dyn for<'b> Fn(FunctionArgs<'_, 'b>) -> Option<LhsValue<'b>>
284-
+ Sync
285-
+ Send
286-
+ 's),
283+
call: &(
284+
dyn for<'b> Fn(FunctionArgs<'_, 'b>) -> Option<LhsValue<'b>> + Sync + Send + 's
285+
),
287286
return_type: Type,
288287
f: impl Fn(LhsValue<'a>) -> I,
289288
) -> CompiledValueResult<'a> {
@@ -338,11 +337,12 @@ impl ValueExpr for FunctionCallExpr {
338337
}
339338
} else {
340339
CompiledValueExpr::new(move |ctx| {
341-
if let Some(value) = call(&mut args.iter().map(|arg| arg.execute(ctx))) {
342-
debug_assert!(value.get_type() == return_type);
343-
Ok(value)
344-
} else {
345-
Err(return_type)
340+
match call(&mut args.iter().map(|arg| arg.execute(ctx))) {
341+
Some(value) => {
342+
debug_assert!(value.get_type() == return_type);
343+
Ok(value)
344+
}
345+
_ => Err(return_type),
346346
}
347347
})
348348
}
@@ -1099,7 +1099,10 @@ mod tests {
10991099
}
11001100
);
11011101

1102-
let expr = FunctionCallArgExpr::lex_with("lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(http.host)))))))))))))))))))))))))))))))) contains \"c\"", &FilterParser::new(&SCHEME));
1102+
let expr = FunctionCallArgExpr::lex_with(
1103+
"lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(lower(http.host)))))))))))))))))))))))))))))))) contains \"c\"",
1104+
&FilterParser::new(&SCHEME),
1105+
);
11031106
assert!(expr.is_ok());
11041107

11051108
let expr = assert_ok!(

engine/src/ast/index_expr.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
use super::{
2+
ValueExpr,
23
field_expr::IdentifierExpr,
34
parse::FilterParser,
45
visitor::{Visitor, VisitorMut},
5-
ValueExpr,
66
};
77
use crate::{
88
compiler::Compiler,
99
execution_context::ExecutionContext,
1010
filter::{
1111
CompiledExpr, CompiledOneExpr, CompiledValueExpr, CompiledVecExpr, CompiledVecExprResult,
1212
},
13-
lex::{expect, skip_space, span, Lex, LexErrorKind, LexResult, LexWith},
13+
lex::{Lex, LexErrorKind, LexResult, LexWith, expect, skip_space, span},
1414
lhs_types::{Array, Map, TypedArray},
1515
scheme::{FieldIndex, IndexAccessError},
1616
types::{GetType, IntoIter, LhsValue, Type},
1717
};
18-
use serde::{ser::SerializeSeq, Serialize, Serializer};
18+
use serde::{Serialize, Serializer, ser::SerializeSeq};
1919

2020
/// IndexExpr is an expr that destructures an index into an IdentifierExpr.
2121
///
@@ -282,10 +282,13 @@ impl IndexExpr {
282282
let call = compiler.compile_function_call_expr(call);
283283
CompiledVecExpr::new(move |ctx| {
284284
let mut iter = MapEachIterator::from_indexes(&indexes[..]);
285-
if let Ok(val) = call.execute(ctx) {
286-
iter.reset(val);
287-
} else {
288-
return TypedArray::default();
285+
match call.execute(ctx) {
286+
Ok(val) => {
287+
iter.reset(val);
288+
}
289+
_ => {
290+
return TypedArray::default();
291+
}
289292
}
290293

291294
TypedArray::from_iter(iter.map(|item| func(&item, ctx)))
@@ -363,7 +366,7 @@ impl<'i, 's> LexWith<'i, &FilterParser<'s>> for IndexExpr {
363366
actual: current_type,
364367
}),
365368
span(input, rest),
366-
))
369+
));
367370
}
368371
},
369372
FieldIndex::MapKey(_) => match current_type {
@@ -377,7 +380,7 @@ impl<'i, 's> LexWith<'i, &FilterParser<'s>> for IndexExpr {
377380
actual: current_type,
378381
}),
379382
span(input, rest),
380-
))
383+
));
381384
}
382385
},
383386
FieldIndex::MapEach => match current_type {
@@ -394,7 +397,7 @@ impl<'i, 's> LexWith<'i, &FilterParser<'s>> for IndexExpr {
394397
actual: current_type,
395398
}),
396399
span(input, rest),
397-
))
400+
));
398401
}
399402
},
400403
};
@@ -544,9 +547,9 @@ impl<'a> Iterator for MapEachIterator<'a, '_> {
544547
mod tests {
545548
use super::*;
546549
use crate::{
547-
ast::field_expr::IdentifierExpr, Array, FieldIndex, FilterParser, FunctionArgKind,
548-
FunctionArgs, FunctionCallArgExpr, FunctionCallExpr, Scheme, SchemeBuilder,
549-
SimpleFunctionDefinition, SimpleFunctionImpl, SimpleFunctionParam,
550+
Array, FieldIndex, FilterParser, FunctionArgKind, FunctionArgs, FunctionCallArgExpr,
551+
FunctionCallExpr, Scheme, SchemeBuilder, SimpleFunctionDefinition, SimpleFunctionImpl,
552+
SimpleFunctionParam, ast::field_expr::IdentifierExpr,
550553
};
551554
use std::sync::LazyLock;
552555

engine/src/ast/logical_expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use super::{
2+
Expr,
23
field_expr::ComparisonExpr,
34
parse::FilterParser,
45
visitor::{Visitor, VisitorMut},
5-
Expr,
66
};
77
use crate::{
88
compiler::Compiler,
99
filter::{CompiledExpr, CompiledOneExpr, CompiledVecExpr},
10-
lex::{expect, skip_space, Lex, LexErrorKind, LexResult, LexWith},
10+
lex::{Lex, LexErrorKind, LexResult, LexWith, expect, skip_space},
1111
types::{GetType, Type, TypeMismatchError},
1212
};
1313
use serde::Serialize;
@@ -69,7 +69,7 @@ pub enum LogicalExpr {
6969
impl GetType for LogicalExpr {
7070
fn get_type(&self) -> Type {
7171
match &self {
72-
LogicalExpr::Combining { ref items, .. } => items[0].get_type(),
72+
LogicalExpr::Combining { items, .. } => items[0].get_type(),
7373
LogicalExpr::Comparison(comparison) => comparison.get_type(),
7474
LogicalExpr::Parenthesized(parenthesized) => parenthesized.expr.get_type(),
7575
LogicalExpr::Unary { arg, .. } => arg.get_type(),
@@ -147,7 +147,7 @@ impl LogicalExpr {
147147
actual: rhsty,
148148
}),
149149
lookahead.1,
150-
))
150+
));
151151
}
152152
}
153153

engine/src/ast/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{FilterAst, FilterValueAst};
22
use crate::{
3-
lex::{complete, LexErrorKind, LexResult, LexWith},
3+
lex::{LexErrorKind, LexResult, LexWith, complete},
44
scheme::Scheme,
55
};
66
use std::cmp::{max, min};

engine/src/ast/visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use super::{
2+
Expr, ValueExpr,
23
field_expr::{ComparisonExpr, ComparisonOpExpr},
34
function_expr::{FunctionCallArgExpr, FunctionCallExpr},
45
index_expr::IndexExpr,
56
logical_expr::LogicalExpr,
6-
Expr, ValueExpr,
77
};
88
use crate::{Field, FieldRef, Function};
99

engine/src/execution_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
2+
FieldRef, ListMatcher, ListRef, UnknownFieldError,
23
scheme::{Field, List, Scheme, SchemeMismatchError},
34
types::{GetType, LhsValue, LhsValueSeed, Type, TypeMismatchError},
4-
FieldRef, ListMatcher, ListRef, UnknownFieldError,
55
};
66
use serde::de::{self, DeserializeSeed, Deserializer, MapAccess, Visitor};
77
use serde::ser::{SerializeMap, SerializeSeq, Serializer};

0 commit comments

Comments
 (0)