@@ -4,6 +4,7 @@ use std::{
44 char:: CharTryFromError ,
55 convert:: TryFrom ,
66 ffi:: CStr ,
7+ num:: { NonZeroI32 , NonZeroI64 , NonZeroI8 , NonZeroU32 , NonZeroU64 , NonZeroU8 } ,
78 path:: { Path , PathBuf } ,
89} ;
910
@@ -2174,87 +2175,36 @@ impl HasParamSpec for char {
21742175 Self :: ParamSpec :: builder
21752176 }
21762177}
2177- impl HasParamSpec for f64 {
2178- type ParamSpec = ParamSpecDouble ;
2179- type SetValue = Self ;
2180- type BuilderFn = fn ( & str ) -> ParamSpecDoubleBuilder ;
2181-
2182- fn param_spec_builder ( ) -> Self :: BuilderFn {
2183- Self :: ParamSpec :: builder
2184- }
2185- }
2186- impl HasParamSpec for f32 {
2187- type ParamSpec = ParamSpecFloat ;
2188- type SetValue = Self ;
2189- type BuilderFn = fn ( & str ) -> ParamSpecFloatBuilder ;
2190-
2191- fn param_spec_builder ( ) -> Self :: BuilderFn {
2192- Self :: ParamSpec :: builder
2193- }
2194- }
2195- impl HasParamSpec for i64 {
2196- type ParamSpec = ParamSpecInt64 ;
2197- type SetValue = Self ;
2198- type BuilderFn = fn ( & str ) -> ParamSpecInt64Builder ;
2199-
2200- fn param_spec_builder ( ) -> Self :: BuilderFn {
2201- Self :: ParamSpec :: builder
2202- }
2203- }
2204- impl HasParamSpec for i32 {
2205- type ParamSpec = ParamSpecInt ;
2206- type SetValue = Self ;
2207- type BuilderFn = fn ( & str ) -> ParamSpecIntBuilder ;
2208-
2209- fn param_spec_builder ( ) -> Self :: BuilderFn {
2210- Self :: ParamSpec :: builder
2211- }
2212- }
2213- impl HasParamSpec for i8 {
2214- type ParamSpec = ParamSpecChar ;
2215- type SetValue = Self ;
2216- type BuilderFn = fn ( & str ) -> ParamSpecCharBuilder ;
2178+ // Simple types which have `type SetValue = Self`
2179+ // and a builder function that doesn't require any parameter except the name
2180+ macro_rules! has_simple_spec {
2181+ ( $t: ty, $s: ty, $b: ty) => {
2182+ impl HasParamSpec for $t {
2183+ type ParamSpec = $s;
2184+ type SetValue = Self ;
2185+ type BuilderFn = fn ( & str ) -> $b;
22172186
2218- fn param_spec_builder ( ) -> Self :: BuilderFn {
2219- Self :: ParamSpec :: builder
2220- }
2221- }
2222- impl HasParamSpec for u64 {
2223- type ParamSpec = ParamSpecUInt64 ;
2224- type SetValue = Self ;
2225- type BuilderFn = fn ( & str ) -> ParamSpecUInt64Builder ;
2226-
2227- fn param_spec_builder ( ) -> Self :: BuilderFn {
2228- Self :: ParamSpec :: builder
2229- }
2230- }
2231- impl HasParamSpec for u32 {
2232- type ParamSpec = ParamSpecUInt ;
2233- type SetValue = Self ;
2234- type BuilderFn = fn ( & str ) -> ParamSpecUIntBuilder ;
2235-
2236- fn param_spec_builder ( ) -> Self :: BuilderFn {
2237- Self :: ParamSpec :: builder
2238- }
2239- }
2240- impl HasParamSpec for u8 {
2241- type ParamSpec = ParamSpecUChar ;
2242- type SetValue = Self ;
2243- type BuilderFn = fn ( & str ) -> ParamSpecUCharBuilder ;
2244-
2245- fn param_spec_builder ( ) -> Self :: BuilderFn {
2246- Self :: ParamSpec :: builder
2247- }
2248- }
2249- impl HasParamSpec for bool {
2250- type ParamSpec = ParamSpecBoolean ;
2251- type SetValue = Self ;
2252- type BuilderFn = fn ( & str ) -> ParamSpecBooleanBuilder ;
2253-
2254- fn param_spec_builder ( ) -> Self :: BuilderFn {
2255- Self :: ParamSpec :: builder
2256- }
2187+ fn param_spec_builder( ) -> Self :: BuilderFn {
2188+ Self :: ParamSpec :: builder
2189+ }
2190+ }
2191+ } ;
22572192}
2193+ has_simple_spec ! ( f64 , ParamSpecDouble , ParamSpecDoubleBuilder ) ;
2194+ has_simple_spec ! ( f32 , ParamSpecFloat , ParamSpecFloatBuilder ) ;
2195+ has_simple_spec ! ( i64 , ParamSpecInt64 , ParamSpecInt64Builder ) ;
2196+ has_simple_spec ! ( NonZeroI64 , ParamSpecInt64 , ParamSpecInt64Builder ) ;
2197+ has_simple_spec ! ( i32 , ParamSpecInt , ParamSpecIntBuilder ) ;
2198+ has_simple_spec ! ( NonZeroI32 , ParamSpecInt , ParamSpecIntBuilder ) ;
2199+ has_simple_spec ! ( i8 , ParamSpecChar , ParamSpecCharBuilder ) ;
2200+ has_simple_spec ! ( NonZeroI8 , ParamSpecChar , ParamSpecCharBuilder ) ;
2201+ has_simple_spec ! ( u64 , ParamSpecUInt64 , ParamSpecUInt64Builder ) ;
2202+ has_simple_spec ! ( NonZeroU64 , ParamSpecUInt64 , ParamSpecUInt64Builder ) ;
2203+ has_simple_spec ! ( u32 , ParamSpecUInt , ParamSpecUIntBuilder ) ;
2204+ has_simple_spec ! ( NonZeroU32 , ParamSpecUInt , ParamSpecUIntBuilder ) ;
2205+ has_simple_spec ! ( u8 , ParamSpecUChar , ParamSpecUCharBuilder ) ;
2206+ has_simple_spec ! ( NonZeroU8 , ParamSpecUChar , ParamSpecUCharBuilder ) ;
2207+ has_simple_spec ! ( bool , ParamSpecBoolean , ParamSpecBooleanBuilder ) ;
22582208
22592209impl HasParamSpec for crate :: Variant {
22602210 type ParamSpec = ParamSpecVariant ;
0 commit comments