These match-expressions are implementing unwrap_or_else
This commit is contained in:
parent
6d31ec521b
commit
57de28744c
@ -29,7 +29,7 @@
|
|||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(
|
allow(
|
||||||
enum_variant_names, redundant_field_names, too_many_arguments, used_underscore_binding,
|
enum_variant_names, redundant_field_names, too_many_arguments, used_underscore_binding,
|
||||||
cyclomatic_complexity
|
cyclomatic_complexity, needless_pass_by_value
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
// Whitelisted clippy_pedantic lints
|
// Whitelisted clippy_pedantic lints
|
||||||
@ -69,17 +69,21 @@ mod try;
|
|||||||
#[proc_macro_derive(Serialize, attributes(serde))]
|
#[proc_macro_derive(Serialize, attributes(serde))]
|
||||||
pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
pub fn derive_serialize(input: TokenStream) -> TokenStream {
|
||||||
let input: DeriveInput = syn::parse(input).unwrap();
|
let input: DeriveInput = syn::parse(input).unwrap();
|
||||||
match ser::expand_derive_serialize(&input) {
|
ser::expand_derive_serialize(&input)
|
||||||
Ok(expanded) => expanded.into(),
|
.unwrap_or_else(compile_error)
|
||||||
Err(msg) => quote! {compile_error!(#msg);}.into(),
|
.into()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[proc_macro_derive(Deserialize, attributes(serde))]
|
#[proc_macro_derive(Deserialize, attributes(serde))]
|
||||||
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
|
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
|
||||||
let input: DeriveInput = syn::parse(input).unwrap();
|
let input: DeriveInput = syn::parse(input).unwrap();
|
||||||
match de::expand_derive_deserialize(&input) {
|
de::expand_derive_deserialize(&input)
|
||||||
Ok(expanded) => expanded.into(),
|
.unwrap_or_else(compile_error)
|
||||||
Err(msg) => quote! {compile_error!(#msg);}.into(),
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compile_error(message: String) -> proc_macro2::TokenStream {
|
||||||
|
quote! {
|
||||||
|
compile_error!(#message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user