@@ -8,7 +8,9 @@ pub use esp32bootloader::*;
8
8
pub use esp32directboot:: * ;
9
9
pub use esp8266:: * ;
10
10
11
- use strum_macros:: { AsStaticStr , Display , EnumString } ;
11
+ use crate :: error:: Error ;
12
+ use std:: str:: FromStr ;
13
+ use strum_macros:: { AsStaticStr , Display , EnumVariantNames } ;
12
14
13
15
const ESP_MAGIC : u8 = 0xE9 ;
14
16
const WP_PIN_DISABLED : u8 = 0xEE ;
@@ -44,10 +46,21 @@ pub trait ImageFormat<'a> {
44
46
' a : ' b ;
45
47
}
46
48
47
- #[ derive( Debug , Copy , Clone , Eq , PartialEq , Display , EnumString , AsStaticStr ) ]
49
+ #[ derive( Debug , Copy , Clone , Eq , PartialEq , Display , AsStaticStr , EnumVariantNames ) ]
50
+ #[ strum( serialize_all = "kebab-case" ) ]
48
51
pub enum ImageFormatId {
49
- #[ strum( serialize = "bootloader" ) ]
50
52
Bootloader ,
51
- #[ strum( serialize = "direct-boot" ) ]
52
53
DirectBoot ,
53
54
}
55
+
56
+ impl FromStr for ImageFormatId {
57
+ type Err = Error ;
58
+
59
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
60
+ match s {
61
+ "bootloader" => Ok ( Self :: Bootloader ) ,
62
+ "direct-boot" => Ok ( Self :: DirectBoot ) ,
63
+ _ => Err ( Error :: UnknownImageFormat ( s. into ( ) ) ) ,
64
+ }
65
+ }
66
+ }
0 commit comments