@@ -7,11 +7,15 @@ use std::{
77 sync:: LazyLock ,
88} ;
99
10- #[ cfg( feature = "darling" ) ]
11- use darling:: FromMeta ;
1210use regex:: Regex ;
1311use snafu:: { OptionExt , ResultExt , Snafu } ;
1412
13+ #[ cfg( feature = "serde" ) ]
14+ mod serde;
15+
16+ #[ cfg( feature = "darling" ) ]
17+ mod darling;
18+
1519static LEVEL_REGEX : LazyLock < Regex > = LazyLock :: new ( || {
1620 Regex :: new ( r"^(?P<identifier>[a-z]+)(?P<version>\d+)$" ) . expect ( "failed to compile level regex" )
1721} ) ;
@@ -148,28 +152,13 @@ impl Display for Level {
148152 }
149153}
150154
151- #[ cfg( feature = "darling" ) ]
152- impl FromMeta for Level {
153- fn from_string ( value : & str ) -> darling:: Result < Self > {
154- Self :: from_str ( value) . map_err ( darling:: Error :: custom)
155- }
156- }
157-
158155#[ cfg( test) ]
159156mod test {
160- #[ cfg( feature = "darling" ) ]
161- use quote:: quote;
162157 use rstest:: rstest;
163158 use rstest_reuse:: * ;
164159
165160 use super :: * ;
166161
167- #[ cfg( feature = "darling" ) ]
168- fn parse_meta ( tokens : proc_macro2:: TokenStream ) -> :: std:: result:: Result < syn:: Meta , String > {
169- let attribute: syn:: Attribute = syn:: parse_quote!( #[ #tokens] ) ;
170- Ok ( attribute. meta )
171- }
172-
173162 #[ template]
174163 #[ rstest]
175164 #[ case( Level :: Beta ( 1 ) , Level :: Alpha ( 1 ) , Ordering :: Greater ) ]
@@ -191,15 +180,4 @@ mod test {
191180 fn partial_ord ( input : Level , other : Level , expected : Ordering ) {
192181 assert_eq ! ( input. partial_cmp( & other) , Some ( expected) )
193182 }
194-
195- #[ cfg( feature = "darling" ) ]
196- #[ rstest]
197- #[ case( quote!( ignore = "alpha12" ) , Level :: Alpha ( 12 ) ) ]
198- #[ case( quote!( ignore = "alpha1" ) , Level :: Alpha ( 1 ) ) ]
199- #[ case( quote!( ignore = "beta1" ) , Level :: Beta ( 1 ) ) ]
200- fn from_meta ( #[ case] input : proc_macro2:: TokenStream , #[ case] expected : Level ) {
201- let meta = parse_meta ( input) . expect ( "valid attribute tokens" ) ;
202- let version = Level :: from_meta ( & meta) . expect ( "level must parse from attribute" ) ;
203- assert_eq ! ( version, expected) ;
204- }
205183}
0 commit comments