@@ -19,7 +19,7 @@ use nom7::branch::alt;
19
19
use nom7:: bytes:: complete:: { is_a, tag, tag_no_case, take_while} ;
20
20
use nom7:: character:: complete:: { char, digit1, hex_digit1} ;
21
21
use nom7:: combinator:: { all_consuming, map_opt, opt, value, verify} ;
22
- use nom7:: error:: { make_error, ErrorKind } ;
22
+ use nom7:: error:: { make_error, Error , ErrorKind } ;
23
23
use nom7:: Err ;
24
24
use nom7:: IResult ;
25
25
@@ -58,15 +58,25 @@ pub struct DetectUintData<T> {
58
58
/// And if this fails, will resort to using the enumeration strings.
59
59
///
60
60
/// Returns Some DetectUintData on success, None on failure
61
- pub fn detect_parse_uint_enum < T1 : DetectIntType , T2 : EnumString < T1 > > ( s : & str ) -> Option < DetectUintData < T1 > > {
61
+ pub fn detect_parse_uint_enum < T1 : DetectIntType , T2 : EnumString < T1 > > (
62
+ s : & str ,
63
+ ) -> Option < DetectUintData < T1 > > {
62
64
if let Ok ( ( _, ctx) ) = detect_parse_uint :: < T1 > ( s) {
63
65
return Some ( ctx) ;
64
66
}
67
+
68
+ // we need to precise the Error type, we get error[E0283]: type annotations needed
69
+ let ( s, neg) = opt ( char:: <_, Error <_>>( '!' ) ) ( s) . ok ( ) ?;
70
+ let mode = if neg. is_some ( ) {
71
+ DetectUintMode :: DetectUintModeNe
72
+ } else {
73
+ DetectUintMode :: DetectUintModeEqual
74
+ } ;
65
75
if let Some ( enum_val) = T2 :: from_str ( s) {
66
76
let ctx = DetectUintData :: < T1 > {
67
77
arg1 : enum_val. into_u ( ) ,
68
78
arg2 : T1 :: min_value ( ) ,
69
- mode : DetectUintMode :: DetectUintModeEqual ,
79
+ mode,
70
80
} ;
71
81
return Some ( ctx) ;
72
82
}
0 commit comments