diff options
author | David Knaack <davidkna@users.noreply.github.com> | 2021-03-31 17:31:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-31 17:31:55 +0200 |
commit | d06ba072a88da96448260ff7c97174a08aad669a (patch) | |
tree | 30ff17a324703e767a8bb19b0114d7d6ca2aea0c /starship_module_config_derive | |
parent | 2b15ca1a157fa21dd7d8432b2c51e1e2ecf87496 (diff) |
feat(config): allow printing default and computed config (#2521)
* feat: allow printing default and computed config
* fix custom modules
* actually fix custom modules
Diffstat (limited to 'starship_module_config_derive')
-rw-r--r-- | starship_module_config_derive/Cargo.toml | 2 | ||||
-rw-r--r-- | starship_module_config_derive/src/lib.rs | 15 |
2 files changed, 2 insertions, 15 deletions
diff --git a/starship_module_config_derive/Cargo.toml b/starship_module_config_derive/Cargo.toml index 4b9e83b75..04352616f 100644 --- a/starship_module_config_derive/Cargo.toml +++ b/starship_module_config_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "starship_module_config_derive" -version = "0.1.2" +version = "0.1.3" edition = "2018" authors = ["Matan Kushner <hello@matchai.me>"] homepage = "https://starship.rs" diff --git a/starship_module_config_derive/src/lib.rs b/starship_module_config_derive/src/lib.rs index 4dd0ed7dc..8594a902a 100644 --- a/starship_module_config_derive/src/lib.rs +++ b/starship_module_config_derive/src/lib.rs @@ -18,29 +18,20 @@ fn impl_module_config(dinput: DeriveInput) -> proc_macro::TokenStream { if let syn::Data::Struct(data) = dinput.data { if let syn::Fields::Named(fields_named) = data.fields { let mut load_tokens = quote! {}; - let mut from_tokens = quote! {}; for field in fields_named.named.iter() { let ident = field.ident.as_ref().unwrap(); - let ty = &field.ty; let new_load_tokens = quote! { if let Some(config_str) = config.get(stringify!(#ident)) { new_module_config.#ident = new_module_config.#ident.load_config(config_str); } }; - let new_from_tokens = quote! { - #ident: config.get(stringify!(#ident)).and_then(<#ty>::from_config)?, - }; load_tokens = quote! { #load_tokens #new_load_tokens }; - from_tokens = quote! { - #from_tokens - #new_from_tokens - } } load_config = quote! { @@ -60,11 +51,7 @@ fn impl_module_config(dinput: DeriveInput) -> proc_macro::TokenStream { }; from_config = quote! { fn from_config(config: &'a toml::Value) -> Option<Self> { - let config = config.as_table()?; - - Some(#struct_ident { - #from_tokens - }) + Some(Self::default().load_config(config)) } }; } |