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(),
);
let use_serde = serde_path
.map(|path| {
quote! {
use #path as _serde;
}
})
.unwrap_or_else(|| {
quote! {
#[allow(unknown_lints)]
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
#[allow(rust_2018_idioms)]
extern crate serde as _serde;
}
});
let use_serde = match serde_path {
Some(path) => quote! {
use #path as _serde;
},
None => quote! {
#[allow(unknown_lints)]
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
#[allow(rust_2018_idioms)]
extern crate serde as _serde;
},
};
quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]