@@ -554,18 +554,37 @@ fn bfield_codec_encode_list<T: BFieldCodec>(elements: Iter<T>) -> Vec<BFieldElem
554554 encoding
555555}
556556
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+
557576impl < T > BFieldCodec for PhantomData < T > {
558577 type Error = BFieldCodecError ;
559578
560579 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 )
565584 }
566585
567586 fn encode ( & self ) -> Vec < BFieldElement > {
568- vec ! [ ]
587+ Vec :: new ( )
569588 }
570589
571590 fn static_length ( ) -> Option < usize > {
@@ -613,23 +632,24 @@ mod tests {
613632 where
614633 T : ' static + BFieldCodec + Eq + Debug + Clone + for < ' a > arbitrary:: Arbitrary < ' a > ,
615634 {
616- fn assert_bfield_codec_properties ( & self ) -> Result < ( ) , TestCaseError > {
635+ fn assert_bfield_codec_properties ( & self ) -> TestCaseResult {
617636 self . assert_static_length_is_equal_to_encoded_length ( ) ?;
618637 self . assert_decoded_encoding_is_self ( ) ?;
619638 self . assert_decoding_too_long_encoding_fails ( ) ?;
620639 self . assert_decoding_too_short_encoding_fails ( ) ?;
621640 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 ( ( ) )
623643 }
624644
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 {
626646 if let Some ( static_len) = T :: static_length ( ) {
627647 prop_assert_eq ! ( static_len, self . encoding. len( ) ) ;
628648 }
629649 Ok ( ( ) )
630650 }
631651
632- fn assert_decoded_encoding_is_self ( & self ) -> Result < ( ) , TestCaseError > {
652+ fn assert_decoded_encoding_is_self ( & self ) -> TestCaseResult {
633653 let Ok ( decoding) = T :: decode ( & self . encoding ) else {
634654 let err = TestCaseError :: Fail ( "decoding canonical encoding must not fail" . into ( ) ) ;
635655 return Err ( err) ;
@@ -638,14 +658,14 @@ mod tests {
638658 Ok ( ( ) )
639659 }
640660
641- fn assert_decoding_too_long_encoding_fails ( & self ) -> Result < ( ) , TestCaseError > {
661+ fn assert_decoding_too_long_encoding_fails ( & self ) -> TestCaseResult {
642662 let mut too_long_encoding = self . encoding . to_owned ( ) ;
643663 too_long_encoding. extend ( self . encoding_lengthener . to_owned ( ) ) ;
644664 prop_assert ! ( T :: decode( & too_long_encoding) . is_err( ) ) ;
645665 Ok ( ( ) )
646666 }
647667
648- fn assert_decoding_too_short_encoding_fails ( & self ) -> Result < ( ) , TestCaseError > {
668+ fn assert_decoding_too_short_encoding_fails ( & self ) -> TestCaseResult {
649669 if self . failure_assertions_for_decoding_too_short_sequence_is_not_meaningful ( ) {
650670 return Ok ( ( ) ) ;
651671 }
@@ -655,7 +675,7 @@ mod tests {
655675 Ok ( ( ) )
656676 }
657677
658- fn modify_each_element_and_assert_decoding_failure ( & self ) -> Result < ( ) , TestCaseError > {
678+ fn modify_each_element_and_assert_decoding_failure ( & self ) -> TestCaseResult {
659679 let mut encoding = self . encoding . to_owned ( ) ;
660680 for i in 0 ..encoding. len ( ) {
661681 let original_value = encoding[ i] ;
@@ -669,9 +689,7 @@ mod tests {
669689 Ok ( ( ) )
670690 }
671691
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 {
675693 if self . failure_assertions_for_decoding_too_short_sequence_is_not_meaningful ( ) {
676694 return Ok ( ( ) ) ;
677695 }
@@ -745,6 +763,7 @@ mod tests {
745763 test_case ! { fn tuples_static_dynamic_size_3 for ( Vec <BFieldElement >, ) : None }
746764 test_case ! { fn tuples_dynamic_static_size for ( Vec <XFieldElement >, Digest ) : None }
747765 test_case ! { fn tuples_dynamic_dynamic_size for ( Vec <XFieldElement >, Vec <Digest >) : None }
766+ test_case ! { fn unit for ( ) : Some ( 0 ) }
748767 test_case ! { fn phantom_data for PhantomData <Tip5 >: Some ( 0 ) }
749768 test_case ! { fn boxed_u32s for Box <u32 >: Some ( 1 ) }
750769 test_case ! { fn tuple_with_boxed_bfe for ( u64 , Box <BFieldElement >) : Some ( 3 ) }
0 commit comments