File tree Expand file tree Collapse file tree 2 files changed +27
-8
lines changed Expand file tree Collapse file tree 2 files changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -183,10 +183,14 @@ fn gen_named_fields(
183183 }
184184 field_tokens. push ( quote ! ( #name: match captures. get( #cap_index) {
185185 Some ( m) => {
186- < #p as std:: str :: FromStr >:: from_str( m. as_str( ) ) . map_err( | e | structre:: Error :: Field {
187- field: #path,
188- error: e. to_string( )
189- } ) ?
186+ Some (
187+ < #p as std:: str :: FromStr >:: from_str(
188+ m. as_str( )
189+ ) . map_err( | e | structre:: Error :: Field {
190+ field: #path,
191+ error: e. to_string( )
192+ } ) ?
193+ )
190194 } ,
191195 None => None ,
192196 } ) ) ;
@@ -250,10 +254,14 @@ fn gen_unnamed_fields(
250254 }
251255 out. push ( quote ! ( match captures. get( #cap_index) {
252256 Some ( m) => {
253- < #p as std:: str :: FromStr >:: from_str( m. as_str( ) ) . map_err( | e | structre:: Error :: Field {
254- field: #path,
255- error: e. to_string( )
256- } ) ?
257+ Some (
258+ < #p as std:: str :: FromStr >:: from_str(
259+ m. as_str( )
260+ ) . map_err( | e | structre:: Error :: Field {
261+ field: #path,
262+ error: e. to_string( )
263+ } ) ?
264+ )
257265 } ,
258266 None => None ,
259267 } ) ) ;
Original file line number Diff line number Diff line change @@ -50,6 +50,17 @@ fn uncapture_named() {
5050 assert_eq ! ( v. a, "a" ) ;
5151}
5252
53+ #[ test]
54+ fn test_struct_opt ( ) {
55+ #[ structre( "(?P<a>a)?" ) ]
56+ struct Parsed {
57+ a : Option < String > ,
58+ }
59+
60+ let v = Parsed :: from_str ( "a" ) . unwrap ( ) ;
61+ assert_eq ! ( v. a. as_ref( ) . map( |x| x. as_str( ) ) , Some ( "a" ) ) ;
62+ }
63+
5364#[ test]
5465fn test_enum ( ) {
5566 #[ structre( "(?P<A>a)|(?P<b>b)" ) ]
You can’t perform that action at this time.
0 commit comments