mirror of
https://github.com/Steffo99/micronfig.git
synced 2024-12-23 04:24:18 +00:00
Use unwrap_or_else
and panic!
instead of expect
and format!
in macros too
This commit is contained in:
parent
acd38f75e4
commit
24069da00f
1 changed files with 5 additions and 5 deletions
|
@ -138,12 +138,12 @@ pub fn config(input: TokenStream) -> TokenStream {
|
||||||
(Conversion::TryFrom, true) => quote! {
|
(Conversion::TryFrom, true) => quote! {
|
||||||
let value: Option<#typ> = value
|
let value: Option<#typ> = value
|
||||||
.map(|v| v.try_into())
|
.map(|v| v.try_into())
|
||||||
.map(|v| v.expect(&format!("to be able to convert {}", #identifier_string)));
|
.map(|v| v.unwrap_or_else(|err| panic!("Couldn't perform conversion `{:?} => {:?}`: {:#?}", v, #identifier_string, err)));
|
||||||
},
|
},
|
||||||
(Conversion::FromStr, true) => quote! {
|
(Conversion::FromStr, true) => quote! {
|
||||||
let value: Option<#typ> = value
|
let value: Option<#typ> = value
|
||||||
.map(|v| v.parse())
|
.map(|v| v.parse())
|
||||||
.map(|v| v.expect(&format!("to be able to parse {}", #identifier_string)));
|
.map(|v| v.unwrap_or_else(|err| panic!("Couldn't perform conversion `{:?} > {:?}`: {:#?}", v, #identifier_string, err)));
|
||||||
},
|
},
|
||||||
(Conversion::From, false) => quote! {
|
(Conversion::From, false) => quote! {
|
||||||
let value: #typ = value
|
let value: #typ = value
|
||||||
|
@ -152,12 +152,12 @@ pub fn config(input: TokenStream) -> TokenStream {
|
||||||
(Conversion::TryFrom, false) => quote! {
|
(Conversion::TryFrom, false) => quote! {
|
||||||
let value: #typ = value
|
let value: #typ = value
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect(&format!("to be able to convert {}", #identifier_string));
|
.unwrap_or_else(|err| panic!("Couldn't perform conversion `{:?} => {:?}`: {:#?}", value, #identifier_string, err));
|
||||||
},
|
},
|
||||||
(Conversion::FromStr, false) => quote! {
|
(Conversion::FromStr, false) => quote! {
|
||||||
let value: #typ = value
|
let value: #typ = value
|
||||||
.parse()
|
.parse()
|
||||||
.expect(&format!("to be able to parse {}", #identifier_string));
|
.unwrap_or_else(|err| panic!("Couldn't perform conversion `{:?} > {:?}`: {:#?}", value, #identifier_string, err));
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ pub fn config(input: TokenStream) -> TokenStream {
|
||||||
true => quote! {},
|
true => quote! {},
|
||||||
false => quote! {
|
false => quote! {
|
||||||
let value: String = value
|
let value: String = value
|
||||||
.expect(&format!("that configuration variable {} was set", #identifier_string));
|
.unwrap_or_else(|_| panic!("Unset configuration variable: {}", #identifier_string));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue