Match on serde_path to handle Some(path) and None

I find this a bit easier to follow than map + unwrap_or_else.
This commit is contained in:
David Tolnay 2019-04-03 09:40:21 -07:00
parent 82bde8d166
commit 4c6cb6e359
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -16,20 +16,17 @@ pub fn wrap_in_const(
Span::call_site(), Span::call_site(),
); );
let use_serde = serde_path let use_serde = match serde_path {
.map(|path| { Some(path) => quote! {
quote! { use #path as _serde;
use #path as _serde; },
} None => quote! {
}) #[allow(unknown_lints)]
.unwrap_or_else(|| { #[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
quote! { #[allow(rust_2018_idioms)]
#[allow(unknown_lints)] extern crate serde as _serde;
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))] },
#[allow(rust_2018_idioms)] };
extern crate serde as _serde;
}
});
quote! { quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]