Skip to content

Commit

Permalink
Match on serde_path to handle Some(path) and None
Browse files Browse the repository at this point in the history
I find this a bit easier to follow than map + unwrap_or_else.
  • Loading branch information
dtolnay committed Apr 3, 2019
1 parent 82bde8d commit 4c6cb6e
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions serde_derive/src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 4c6cb6e

Please sign in to comment.