@@ -7,7 +7,7 @@ use alloy_primitives::TxNumber;
77use core:: { ops:: RangeInclusive , str:: FromStr } ;
88use derive_more:: Display ;
99use serde:: { Deserialize , Serialize } ;
10- use strum:: { AsRefStr , EnumIs , EnumString } ;
10+ use strum:: { EnumIs , EnumString } ;
1111
1212#[ derive(
1313 Debug ,
@@ -21,28 +21,27 @@ use strum::{AsRefStr, EnumIs, EnumString};
2121 Deserialize ,
2222 Serialize ,
2323 EnumString ,
24- AsRefStr ,
2524 Display ,
2625 EnumIs ,
2726) ]
27+ #[ strum( serialize_all = "kebab-case" ) ]
2828#[ cfg_attr( feature = "clap" , derive( clap:: ValueEnum ) ) ]
2929/// Segment of the data that can be moved to static files.
3030pub enum StaticFileSegment {
31- #[ strum( serialize = "headers" ) ]
3231 /// Static File segment responsible for the `CanonicalHeaders`, `Headers`,
3332 /// `HeaderTerminalDifficulties` tables.
3433 Headers ,
35- #[ strum( serialize = "transactions" ) ]
3634 /// Static File segment responsible for the `Transactions` table.
3735 Transactions ,
38- #[ strum( serialize = "receipts" ) ]
3936 /// Static File segment responsible for the `Receipts` table.
4037 Receipts ,
4138}
4239
4340impl StaticFileSegment {
4441 /// Returns the segment as a string.
4542 pub const fn as_str ( & self ) -> & ' static str {
43+ // `strum` doesn't generate a doc comment for `into_str` when using `IntoStaticStr` derive
44+ // macro, so we need to manually implement it.
4645 match self {
4746 Self :: Headers => "headers" ,
4847 Self :: Transactions => "transactions" ,
@@ -73,7 +72,7 @@ impl StaticFileSegment {
7372 pub fn filename ( & self , block_range : & SegmentRangeInclusive ) -> String {
7473 // ATTENTION: if changing the name format, be sure to reflect those changes in
7574 // [`Self::parse_filename`].
76- format ! ( "static_file_{}_{}_{}" , self . as_ref ( ) , block_range. start( ) , block_range. end( ) )
75+ format ! ( "static_file_{}_{}_{}" , self . as_str ( ) , block_range. start( ) , block_range. end( ) )
7776 }
7877
7978 /// Returns file name for the provided segment and range, alongside filters, compression.
@@ -473,4 +472,36 @@ mod tests {
473472 ) ;
474473 }
475474 }
475+
476+ /// Used in filename writing/parsing
477+ #[ test]
478+ fn test_static_file_segment_str_roundtrip ( ) {
479+ for segment in StaticFileSegment :: iter ( ) {
480+ let static_str = segment. as_str ( ) ;
481+ assert_eq ! ( StaticFileSegment :: from_str( static_str) . unwrap( ) , segment) ;
482+
483+ let expected_str = match segment {
484+ StaticFileSegment :: Headers => "headers" ,
485+ StaticFileSegment :: Transactions => "transactions" ,
486+ StaticFileSegment :: Receipts => "receipts" ,
487+ } ;
488+ assert_eq ! ( static_str, expected_str) ;
489+ }
490+ }
491+
492+ /// Used in segment headers serialize/deserialize
493+ #[ test]
494+ fn test_static_file_segment_serde_roundtrip ( ) {
495+ for segment in StaticFileSegment :: iter ( ) {
496+ let ser = serde_json:: to_string ( & segment) . unwrap ( ) ;
497+ assert_eq ! ( serde_json:: from_str:: <StaticFileSegment >( & ser) . unwrap( ) , segment) ;
498+
499+ let expected_str = match segment {
500+ StaticFileSegment :: Headers => "Headers" ,
501+ StaticFileSegment :: Transactions => "Transactions" ,
502+ StaticFileSegment :: Receipts => "Receipts" ,
503+ } ;
504+ assert_eq ! ( ser, format!( "\" {expected_str}\" " ) ) ;
505+ }
506+ }
476507}
0 commit comments