@@ -30,11 +30,8 @@ pub fn parse_sub_attributes(attributes: &[syn::Attribute], main_attribute: &str,
30
30
syn:: Meta :: Path ( _) => { }
31
31
syn:: Meta :: List ( _) => { }
32
32
syn:: Meta :: NameValue ( nv) => {
33
- match ( nv. path . get_ident ( ) , & nv. lit ) {
34
- ( Some ( key) , syn:: Lit :: Str ( lit) ) => {
35
- r. push ( ( key. to_string ( ) , lit. value ( ) ) ) ;
36
- } ,
37
- ( _, _) => ( )
33
+ if let ( Some ( key) , syn:: Lit :: Str ( lit) ) = ( nv. path . get_ident ( ) , & nv. lit ) {
34
+ r. push ( ( key. to_string ( ) , lit. value ( ) ) ) ;
38
35
}
39
36
}
40
37
}
@@ -52,7 +49,7 @@ pub fn parse_sub_attributes(attributes: &[syn::Attribute], main_attribute: &str,
52
49
}
53
50
54
51
55
- #[ derive( Clone , Copy , Debug , PartialEq ) ]
52
+ #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
56
53
/// https://en.wikipedia.org/wiki/Bit_numbering
57
54
pub enum BitNumbering {
58
55
Lsb0 ,
@@ -184,7 +181,7 @@ fn get_field_mid_positioning(field: &syn::Field) -> syn::Result<FieldMidPosition
184
181
} else if let Some ( bits) = field_attributes. iter ( ) . filter_map ( |a| if let PackFieldAttribute :: ElementSizeBits ( bits) = * a { Some ( bits) } else { None } ) . next ( ) {
185
182
bits * array_size
186
183
} else if let BitsPositionParsed :: Range ( a, b) = bits_position {
187
- ( b as isize - a as isize ) . abs ( ) as usize + 1
184
+ ( b as isize - a as isize ) . unsigned_abs ( ) as usize + 1
188
185
} else if let Some ( bit_width_builtin) = bit_width_builtin {
189
186
// todo: is it even possible to hit this branch?
190
187
bit_width_builtin * array_size
@@ -205,7 +202,7 @@ fn parse_field(field: &syn::Field, mp: &FieldMidPositioning, bit_range: &Range<u
205
202
syn:: Type :: Path ( _) => {
206
203
return Ok (
207
204
FieldKind :: Regular {
208
- field : parse_reg_field ( field, & field. ty , bit_range, default_endianness) ?,
205
+ field : Box :: new ( parse_reg_field ( field, & field. ty , bit_range, default_endianness) ?) ,
209
206
ident : field. ident . clone ( ) . ok_or_else ( || syn:: Error :: new ( field. span ( ) , "Missing ident!" ) ) ?
210
207
}
211
208
) ;
@@ -319,7 +316,7 @@ fn parse_reg_field(field: &syn::Field, ty: &syn::Type, bit_range: &Range<usize>,
319
316
320
317
321
318
322
- #[ derive( Copy , Clone , Debug , PartialEq ) ]
319
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
323
320
pub enum BitsPositionParsed {
324
321
Next ,
325
322
Start ( usize ) ,
@@ -442,7 +439,7 @@ pub fn parse_struct(ast: &syn::DeriveInput) -> syn::Result<PackStruct> {
442
439
443
440
let num_bytes = ( num_bits as f32 / 8.0 ) . ceil ( ) as usize ;
444
441
445
- if first_field_is_auto_positioned && ( num_bits % 8 ) != 0 && struct_size_bytes == None {
442
+ if first_field_is_auto_positioned && ( num_bits % 8 ) != 0 && struct_size_bytes. is_none ( ) {
446
443
return Err ( syn:: Error :: new ( fields[ 0 ] . span ( ) , "Please explicitly position the bits of the first field of this structure, as the alignment isn't obvious to the end user." ) ) ;
447
444
}
448
445
@@ -468,7 +465,7 @@ pub fn parse_struct(ast: &syn::DeriveInput) -> syn::Result<PackStruct> {
468
465
} ,
469
466
FieldKind :: Array { ref ident, ref elements, .. } => {
470
467
for ( i, field) in elements. iter ( ) . enumerate ( ) {
471
- find_overlaps ( format ! ( "{}[{}]" , ident. to_string ( ) , i) , & field. bit_range ) ?;
468
+ find_overlaps ( format ! ( "{}[{}]" , ident, i) , & field. bit_range ) ?;
472
469
}
473
470
}
474
471
}
0 commit comments