Skip to content

Commit 4c6cb6e

Browse files
committedApr 3, 2019
Match on serde_path to handle Some(path) and None
I find this a bit easier to follow than map + unwrap_or_else.
1 parent 82bde8d commit 4c6cb6e

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed
 

‎serde_derive/src/dummy.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,17 @@ pub fn wrap_in_const(
1616
Span::call_site(),
1717
);
1818

19-
let use_serde = serde_path
20-
.map(|path| {
21-
quote! {
22-
use #path as _serde;
23-
}
24-
})
25-
.unwrap_or_else(|| {
26-
quote! {
27-
#[allow(unknown_lints)]
28-
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
29-
#[allow(rust_2018_idioms)]
30-
extern crate serde as _serde;
31-
}
32-
});
19+
let use_serde = match serde_path {
20+
Some(path) => quote! {
21+
use #path as _serde;
22+
},
23+
None => quote! {
24+
#[allow(unknown_lints)]
25+
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
26+
#[allow(rust_2018_idioms)]
27+
extern crate serde as _serde;
28+
},
29+
};
3330

3431
quote! {
3532
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]

0 commit comments

Comments
 (0)
Please sign in to comment.