mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-27 03:42:39 +00:00
refactor: ModuleConfig: Simplify generated from_config()
implementations (#775)
We can use `and_then()` to string `Option` values together so that we only need a single `?` assertion. This makes it generally possible to have e.g. `unwrap_or()` at the end.
This commit is contained in:
parent
c4ed88952c
commit
9a1569444b
@ -33,7 +33,7 @@ fn impl_module_config(dinput: DeriveInput) -> proc_macro::TokenStream {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let new_from_tokens = quote! {
|
let new_from_tokens = quote! {
|
||||||
#ident: <#ty>::from_config(config.get(stringify!(#ident))?)?,
|
#ident: config.get(stringify!(#ident)).and_then(<#ty>::from_config)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
load_tokens = quote! {
|
load_tokens = quote! {
|
||||||
|
Loading…
Reference in New Issue
Block a user