aboutsummaryrefslogtreecommitdiff
path: root/alacritty_config/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'alacritty_config/src/lib.rs')
-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)
}
}