@@ -142,12 +142,11 @@ impl WhatAmIMatcher {
142
142
Self :: U8_R => WhatAmI :: STR_R ,
143
143
Self :: U8_P => WhatAmI :: STR_P ,
144
144
Self :: U8_C => WhatAmI :: STR_C ,
145
- Self :: U8_R_P => formatcp ! ( "[{},{}]" , WhatAmI :: STR_R , WhatAmI :: STR_P ) ,
146
- Self :: U8_R_C => formatcp ! ( "[{},{}]" , WhatAmI :: STR_R , WhatAmI :: STR_C ) ,
147
- Self :: U8_P_C => formatcp ! ( "[{},{}]" , WhatAmI :: STR_P , WhatAmI :: STR_C ) ,
148
- Self :: U8_R_P_C => {
149
- formatcp ! ( "[{},{},{}]" , WhatAmI :: STR_R , WhatAmI :: STR_P , WhatAmI :: STR_C )
150
- }
145
+ Self :: U8_R_P => formatcp ! ( "{}|{}" , WhatAmI :: STR_R , WhatAmI :: STR_P ) ,
146
+ Self :: U8_R_C => formatcp ! ( "{}|{}" , WhatAmI :: STR_R , WhatAmI :: STR_C ) ,
147
+ Self :: U8_P_C => formatcp ! ( "{}|{}" , WhatAmI :: STR_P , WhatAmI :: STR_C ) ,
148
+ Self :: U8_R_P_C => formatcp ! ( "{}|{}|{}" , WhatAmI :: STR_R , WhatAmI :: STR_P , WhatAmI :: STR_C ) ,
149
+
151
150
_ => unreachable ! ( ) ,
152
151
}
153
152
}
@@ -188,6 +187,24 @@ impl TryFrom<u8> for WhatAmIMatcher {
188
187
}
189
188
}
190
189
190
+ impl FromStr for WhatAmIMatcher {
191
+ type Err = ( ) ;
192
+
193
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
194
+ let mut inner = 0 ;
195
+ for s in s. split ( '|' ) {
196
+ match s. trim ( ) {
197
+ "" => { }
198
+ WhatAmI :: STR_R => inner |= WhatAmI :: U8_R ,
199
+ WhatAmI :: STR_P => inner |= WhatAmI :: U8_P ,
200
+ WhatAmI :: STR_C => inner |= WhatAmI :: U8_C ,
201
+ _ => return Err ( ( ) ) ,
202
+ }
203
+ }
204
+ Self :: try_from ( inner)
205
+ }
206
+ }
207
+
191
208
impl fmt:: Display for WhatAmIMatcher {
192
209
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
193
210
f. write_str ( self . to_str ( ) )
0 commit comments