@@ -375,15 +375,6 @@ mod tests {
375
375
assert_eq ! ( nla_align!( get_len( ) - 3 ) , usize :: MAX ) ;
376
376
}
377
377
378
- // compile-time test: it should be possible to pass &[u8] through
379
- // NlasIterator and return one of its output &[u8]s without facing
380
- // compiler error about lifetimes and returning borrows from something
381
- // that this funciton owns
382
- fn last_nla_from_buffer ( nlas : & [ u8 ] ) -> Option < Result < & [ u8 ] , DecodeError > > {
383
- NlasIterator :: new ( nlas) . last ( )
384
- . map ( |nla| nla. map ( |nla| nla. value ( ) ) )
385
- }
386
-
387
378
#[ test]
388
379
fn test_nlas_iterator ( ) {
389
380
// sample NFTA_LIST_ELEM from nftables, with nested nlas at the end
@@ -395,15 +386,33 @@ mod tests {
395
386
0x1b , 0x0c , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x8e , 0x14 ,
396
387
0x56 , 0x39
397
388
] ;
398
- let mut iter = NlasIterator :: new ( NESTED_NLAS ) ;
399
- // DecodeError does not implement PartialEq, hence
400
- // unwrap() and is_none()
401
- assert_eq ! ( iter. next( ) . unwrap( ) . unwrap( ) . value( ) , & NESTED_NLAS [ 4 ..12 ] ) ;
402
- assert_eq ! ( iter. next( ) . unwrap( ) . unwrap( ) . value( ) , & NESTED_NLAS [ 16 ..] ) ;
403
- assert ! ( iter. next( ) . is_none( ) ) ;
389
+
390
+ let last = {
391
+ let mut iter = NlasIterator :: new ( NESTED_NLAS ) ;
392
+
393
+ // DecodeError does not implement PartialEq, hence
394
+ // unwrap() and is_none()
395
+
396
+ assert_eq ! (
397
+ iter. next( ) . unwrap( ) . unwrap( ) . value( ) ,
398
+ & NESTED_NLAS [ 4 ..12 ]
399
+ ) ;
400
+
401
+ // it should be possible to pass &[u8] through
402
+ // NlasIterator and return one of its output &[u8]s without facing
403
+ // compiler error about lifetimes and returning borrows from
404
+ // something that this funciton owns
405
+ let last = iter. next ( ) . unwrap ( ) . unwrap ( ) . value ( ) ;
406
+ // asserted later
407
+
408
+ assert ! ( iter. next( ) . is_none( ) ) ;
409
+
410
+ last
411
+ } ;
412
+ assert_eq ! ( last, & NESTED_NLAS [ 16 ..] ) ;
404
413
405
414
// this sholud be an Err()
406
415
let truncated = & NESTED_NLAS [ .. NESTED_NLAS . len ( ) -1 ] ;
407
- assert ! ( last_nla_from_buffer ( truncated) . unwrap( ) . is_err( ) ) ;
416
+ assert ! ( NlasIterator :: new ( truncated) . last ( ) . unwrap( ) . is_err( ) ) ;
408
417
}
409
418
}
0 commit comments