diff options
author | Christian Duerr <contact@christianduerr.com> | 2023-06-15 10:59:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-15 08:59:12 +0000 |
commit | afffdbe612cb8b573016184400e0deeb0137ccb9 (patch) | |
tree | 3f79b638ec3e5c8f85f2ba784898ee1fa9034322 /alacritty_config_derive/src | |
parent | be03effdbe5b5bdabfed50d87963e78017329182 (diff) | |
download | alacritty-afffdbe612cb8b573016184400e0deeb0137ccb9.tar.gz alacritty-afffdbe612cb8b573016184400e0deeb0137ccb9.zip |
Fix `alacritty msg config` toml replacement
This fixes a regression introduced in bd49067 which broke the override
of configuration file variables using `alacritty msg config`.
To fix this the `replace` functionality was rewritten to behave more
like the `serde_utils::merge` where entire values are inserted into the
existing structure rather than separating the keys from the values.
Fixes: bd49067 (Switch to TOML configuration format)
Diffstat (limited to 'alacritty_config_derive/src')
-rw-r--r-- | alacritty_config_derive/src/serde_replace.rs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/alacritty_config_derive/src/serde_replace.rs b/alacritty_config_derive/src/serde_replace.rs index 7ca5ca7c..0a703b4c 100644 --- a/alacritty_config_derive/src/serde_replace.rs +++ b/alacritty_config_derive/src/serde_replace.rs @@ -28,11 +28,7 @@ pub fn derive(input: TokenStream) -> TokenStream { pub fn derive_direct(ident: Ident, generics: Generics) -> TokenStream2 { quote! { impl <#generics> alacritty_config::SerdeReplace for #ident <#generics> { - fn replace(&mut self, key: &str, value: toml::Value) -> Result<(), Box<dyn std::error::Error>> { - if !key.is_empty() { - let error = format!("Fields \"{}\" do not exist", key); - return Err(error.into()); - } + fn replace(&mut self, value: toml::Value) -> Result<(), Box<dyn std::error::Error>> { *self = serde::Deserialize::deserialize(value)?; Ok(()) @@ -53,19 +49,23 @@ pub fn derive_recursive<T>( quote! { #[allow(clippy::extra_unused_lifetimes)] impl <'de, #constrained> alacritty_config::SerdeReplace for #ident <#unconstrained> { - fn replace(&mut self, key: &str, value: toml::Value) -> Result<(), Box<dyn std::error::Error>> { - if key.is_empty() { - *self = serde::Deserialize::deserialize(value)?; - return Ok(()); - } - - let (field, next_key) = key.split_once('.').unwrap_or((key, "")); - match field { - #replace_arms - _ => { - let error = format!("Field \"{}\" does not exist", field); - return Err(error.into()); + fn replace(&mut self, value: toml::Value) -> Result<(), Box<dyn std::error::Error>> { + match value.as_table() { + Some(table) => { + for (field, next_value) in table { + let next_value = next_value.clone(); + let value = value.clone(); + + match field.as_str() { + #replace_arms + _ => { + let error = format!("Field \"{}\" does not exist", field); + return Err(error.into()); + }, + } + } }, + None => *self = serde::Deserialize::deserialize(value)?, } Ok(()) @@ -95,11 +95,11 @@ fn match_arms<T>(fields: &Punctuated<Field, T>) -> TokenStream2 { return Error::new(ident.span(), MULTIPLE_FLATTEN_ERROR).to_compile_error(); } else if flatten { flattened_arm = Some(quote! { - _ => alacritty_config::SerdeReplace::replace(&mut self.#ident, key, value)?, + _ => alacritty_config::SerdeReplace::replace(&mut self.#ident, value)?, }); } else { stream.extend(quote! { - #literal => alacritty_config::SerdeReplace::replace(&mut self.#ident, next_key, value)?, + #literal => alacritty_config::SerdeReplace::replace(&mut self.#ident, next_value)?, }); } } |