@@ -554,18 +554,37 @@ fn bfield_codec_encode_list<T: BFieldCodec>(elements: Iter<T>) -> Vec<BFieldElem
554
554
encoding
555
555
}
556
556
557
+ impl BFieldCodec for ( ) {
558
+ type Error = BFieldCodecError ;
559
+
560
+ fn decode ( sequence : & [ BFieldElement ] ) -> Result < Box < Self > , Self :: Error > {
561
+ sequence
562
+ . is_empty ( )
563
+ . then ( || Box :: new ( ( ) ) )
564
+ . ok_or_else ( || BFieldCodecError :: SequenceTooLong )
565
+ }
566
+
567
+ fn encode ( & self ) -> Vec < BFieldElement > {
568
+ Vec :: new ( )
569
+ }
570
+
571
+ fn static_length ( ) -> Option < usize > {
572
+ Some ( 0 )
573
+ }
574
+ }
575
+
557
576
impl < T > BFieldCodec for PhantomData < T > {
558
577
type Error = BFieldCodecError ;
559
578
560
579
fn decode ( sequence : & [ BFieldElement ] ) -> Result < Box < Self > , Self :: Error > {
561
- if ! sequence. is_empty ( ) {
562
- return Err ( Self :: Error :: SequenceTooLong ) ;
563
- }
564
- Ok ( Box :: new ( PhantomData ) )
580
+ sequence
581
+ . is_empty ( )
582
+ . then ( || Box :: new ( PhantomData ) )
583
+ . ok_or_else ( || BFieldCodecError :: SequenceTooLong )
565
584
}
566
585
567
586
fn encode ( & self ) -> Vec < BFieldElement > {
568
- vec ! [ ]
587
+ Vec :: new ( )
569
588
}
570
589
571
590
fn static_length ( ) -> Option < usize > {
@@ -613,23 +632,24 @@ mod tests {
613
632
where
614
633
T : ' static + BFieldCodec + Eq + Debug + Clone + for < ' a > arbitrary:: Arbitrary < ' a > ,
615
634
{
616
- fn assert_bfield_codec_properties ( & self ) -> Result < ( ) , TestCaseError > {
635
+ fn assert_bfield_codec_properties ( & self ) -> TestCaseResult {
617
636
self . assert_static_length_is_equal_to_encoded_length ( ) ?;
618
637
self . assert_decoded_encoding_is_self ( ) ?;
619
638
self . assert_decoding_too_long_encoding_fails ( ) ?;
620
639
self . assert_decoding_too_short_encoding_fails ( ) ?;
621
640
self . modify_each_element_and_assert_decoding_failure ( ) ?;
622
- self . assert_decoding_random_too_short_encoding_fails_gracefully ( )
641
+ self . assert_decoding_random_too_short_encoding_fails_gracefully ( ) ?;
642
+ Ok ( ( ) )
623
643
}
624
644
625
- fn assert_static_length_is_equal_to_encoded_length ( & self ) -> Result < ( ) , TestCaseError > {
645
+ fn assert_static_length_is_equal_to_encoded_length ( & self ) -> TestCaseResult {
626
646
if let Some ( static_len) = T :: static_length ( ) {
627
647
prop_assert_eq ! ( static_len, self . encoding. len( ) ) ;
628
648
}
629
649
Ok ( ( ) )
630
650
}
631
651
632
- fn assert_decoded_encoding_is_self ( & self ) -> Result < ( ) , TestCaseError > {
652
+ fn assert_decoded_encoding_is_self ( & self ) -> TestCaseResult {
633
653
let Ok ( decoding) = T :: decode ( & self . encoding ) else {
634
654
let err = TestCaseError :: Fail ( "decoding canonical encoding must not fail" . into ( ) ) ;
635
655
return Err ( err) ;
@@ -638,14 +658,14 @@ mod tests {
638
658
Ok ( ( ) )
639
659
}
640
660
641
- fn assert_decoding_too_long_encoding_fails ( & self ) -> Result < ( ) , TestCaseError > {
661
+ fn assert_decoding_too_long_encoding_fails ( & self ) -> TestCaseResult {
642
662
let mut too_long_encoding = self . encoding . to_owned ( ) ;
643
663
too_long_encoding. extend ( self . encoding_lengthener . to_owned ( ) ) ;
644
664
prop_assert ! ( T :: decode( & too_long_encoding) . is_err( ) ) ;
645
665
Ok ( ( ) )
646
666
}
647
667
648
- fn assert_decoding_too_short_encoding_fails ( & self ) -> Result < ( ) , TestCaseError > {
668
+ fn assert_decoding_too_short_encoding_fails ( & self ) -> TestCaseResult {
649
669
if self . failure_assertions_for_decoding_too_short_sequence_is_not_meaningful ( ) {
650
670
return Ok ( ( ) ) ;
651
671
}
@@ -655,7 +675,7 @@ mod tests {
655
675
Ok ( ( ) )
656
676
}
657
677
658
- fn modify_each_element_and_assert_decoding_failure ( & self ) -> Result < ( ) , TestCaseError > {
678
+ fn modify_each_element_and_assert_decoding_failure ( & self ) -> TestCaseResult {
659
679
let mut encoding = self . encoding . to_owned ( ) ;
660
680
for i in 0 ..encoding. len ( ) {
661
681
let original_value = encoding[ i] ;
@@ -669,9 +689,7 @@ mod tests {
669
689
Ok ( ( ) )
670
690
}
671
691
672
- fn assert_decoding_random_too_short_encoding_fails_gracefully (
673
- & self ,
674
- ) -> Result < ( ) , TestCaseError > {
692
+ fn assert_decoding_random_too_short_encoding_fails_gracefully ( & self ) -> TestCaseResult {
675
693
if self . failure_assertions_for_decoding_too_short_sequence_is_not_meaningful ( ) {
676
694
return Ok ( ( ) ) ;
677
695
}
@@ -745,6 +763,7 @@ mod tests {
745
763
test_case ! { fn tuples_static_dynamic_size_3 for ( Vec <BFieldElement >, ) : None }
746
764
test_case ! { fn tuples_dynamic_static_size for ( Vec <XFieldElement >, Digest ) : None }
747
765
test_case ! { fn tuples_dynamic_dynamic_size for ( Vec <XFieldElement >, Vec <Digest >) : None }
766
+ test_case ! { fn unit for ( ) : Some ( 0 ) }
748
767
test_case ! { fn phantom_data for PhantomData <Tip5 >: Some ( 0 ) }
749
768
test_case ! { fn boxed_u32s for Box <u32 >: Some ( 1 ) }
750
769
test_case ! { fn tuple_with_boxed_bfe for ( u64 , Box <BFieldElement >) : Some ( 3 ) }
0 commit comments