@@ -17,10 +17,13 @@ pub(crate) struct TlvRecord {
1717#[ macro_export]
1818macro_rules! define_tlv_enum {
1919 (
20+ $( #[ $meta: meta] ) *
2021 $vis: vis enum $enum_name: ident {
2122 $( $typ: literal => $variant: ident( $inner: ty) ) ,* $( , ) ?
2223 }
2324 ) => {
25+ // add the doc-comment if present
26+ $( #[ $meta] ) *
2427 // define the enum itself
2528 #[ derive( Debug , Clone , Eq , PartialEq ) ]
2629 $vis enum $enum_name {
@@ -44,7 +47,7 @@ macro_rules! define_tlv_enum {
4447 impl TryFrom <& TlvRecord > for $enum_name {
4548 type Error = bincode:: Error ;
4649 fn try_from( value: & TlvRecord ) -> Result <Self , Self :: Error > {
47- use serde:: ser :: Error ;
50+ use serde:: de :: Error ;
4851 match value. typ {
4952 $(
5053 $typ => Ok ( Self :: $variant( bincode:: deserialize:: <$inner>( & value. bytes) ?) ) ,
@@ -57,13 +60,16 @@ macro_rules! define_tlv_enum {
5760 impl TryFrom <& $enum_name> for TlvRecord {
5861 type Error = bincode:: Error ;
5962 fn try_from( value: & $enum_name) -> Result <Self , Self :: Error > {
63+ use serde:: ser:: Error ;
6064 match value {
6165 $(
6266 $enum_name:: $variant( inner) => Ok ( TlvRecord {
6367 typ: $typ,
6468 bytes: bincode:: serialize( inner) ?,
6569 } ) ,
6670 ) *
71+ #[ allow( unreachable_patterns) ]
72+ _ => Err ( bincode:: Error :: custom( "Unsupported enum variant" ) ) ,
6773 }
6874 }
6975 }
@@ -114,7 +120,11 @@ mod tests {
114120 // Make sure legacy recover works correctly
115121 let legacy: Vec < ExtensionLegacy > = crate :: tlv:: parse ( & tlv_vec) ;
116122 assert ! ( matches!( legacy[ 0 ] , ExtensionLegacy :: Test ( 42 ) ) ) ;
117- assert_eq ! ( legacy. len( ) , 1 , "Legacy parser should only recover " )
123+ assert_eq ! (
124+ legacy. len( ) ,
125+ 1 ,
126+ "Legacy parser should only recover 1 entry"
127+ )
118128 }
119129
120130 /// Test that TLV encoded data is forwards-compatible,
0 commit comments