mirror of
https://github.com/starship/starship.git
synced 2026-06-22 02:02:12 +07: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:
committed by
Matan Kushner
parent
c4ed88952c
commit
9a1569444b
@@ -33,7 +33,7 @@ fn impl_module_config(dinput: DeriveInput) -> proc_macro::TokenStream {
|
||||
}
|
||||
};
|
||||
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! {
|
||||
|
||||
Reference in New Issue
Block a user