aboutsummaryrefslogtreecommitdiff
path: root/alacritty_config
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2023-06-15 10:59:12 +0200
committerGitHub <noreply@github.com>2023-06-15 08:59:12 +0000
commitafffdbe612cb8b573016184400e0deeb0137ccb9 (patch)
tree3f79b638ec3e5c8f85f2ba784898ee1fa9034322 /alacritty_config
parentbe03effdbe5b5bdabfed50d87963e78017329182 (diff)
downloadalacritty-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')
-rw-r--r--alacritty_config/src/lib.rs24
1 files changed, 10 insertions, 14 deletions
diff --git a/alacritty_config/src/lib.rs b/alacritty_config/src/lib.rs
index c9d73622..1e5282d7 100644
--- a/alacritty_config/src/lib.rs
+++ b/alacritty_config/src/lib.rs
@@ -6,15 +6,15 @@ use serde::Deserialize;
use toml::Value;
pub trait SerdeReplace {
- fn replace(&mut self, key: &str, value: Value) -> Result<(), Box<dyn Error>>;
+ fn replace(&mut self, value: Value) -> Result<(), Box<dyn Error>>;
}
macro_rules! impl_replace {
($($ty:ty),*$(,)*) => {
$(
impl SerdeReplace for $ty {
- fn replace(&mut self, key: &str, value: Value) -> Result<(), Box<dyn Error>> {
- replace_simple(self, key, value)
+ fn replace(&mut self, value: Value) -> Result<(), Box<dyn Error>> {
+ replace_simple(self, value)
}
}
)*
@@ -35,33 +35,29 @@ impl_replace!(
#[cfg(target_os = "macos")]
impl_replace!(winit::platform::macos::OptionAsAlt,);
-fn replace_simple<'de, D>(data: &mut D, key: &str, value: Value) -> Result<(), Box<dyn Error>>
+fn replace_simple<'de, D>(data: &mut D, value: Value) -> Result<(), Box<dyn Error>>
where
D: Deserialize<'de>,
{
- if !key.is_empty() {
- let error = format!("Fields \"{key}\" do not exist");
- return Err(error.into());
- }
*data = D::deserialize(value)?;
Ok(())
}
impl<'de, T: Deserialize<'de>> SerdeReplace for Vec<T> {
- fn replace(&mut self, key: &str, value: Value) -> Result<(), Box<dyn Error>> {
- replace_simple(self, key, value)
+ fn replace(&mut self, value: Value) -> Result<(), Box<dyn Error>> {
+ replace_simple(self, value)
}
}
impl<'de, T: Deserialize<'de>> SerdeReplace for Option<T> {
- fn replace(&mut self, key: &str, value: Value) -> Result<(), Box<dyn Error>> {
- replace_simple(self, key, value)
+ fn replace(&mut self, value: Value) -> Result<(), Box<dyn Error>> {
+ replace_simple(self, value)
}
}
impl<'de, T: Deserialize<'de>> SerdeReplace for HashMap<String, T> {
- fn replace(&mut self, key: &str, value: Value) -> Result<(), Box<dyn Error>> {
- replace_simple(self, key, value)
+ fn replace(&mut self, value: Value) -> Result<(), Box<dyn Error>> {
+ replace_simple(self, value)
}
}