aboutsummaryrefslogtreecommitdiff
path: root/alacritty_config_derive/src
diff options
context:
space:
mode:
Diffstat (limited to 'alacritty_config_derive/src')
-rw-r--r--alacritty_config_derive/src/config_deserialize/de_struct.rs26
-rw-r--r--alacritty_config_derive/src/serde_replace.rs4
2 files changed, 21 insertions, 9 deletions
diff --git a/alacritty_config_derive/src/config_deserialize/de_struct.rs b/alacritty_config_derive/src/config_deserialize/de_struct.rs
index 1846f925..d2a7dd82 100644
--- a/alacritty_config_derive/src/config_deserialize/de_struct.rs
+++ b/alacritty_config_derive/src/config_deserialize/de_struct.rs
@@ -42,20 +42,25 @@ pub fn derive_deserialize<T>(
{
let mut config = Self::Value::default();
- // NOTE: This could be used to print unused keys.
- let mut unused = serde_yaml::Mapping::new();
+ // Unused keys for flattening and warning.
+ let mut unused = toml::Table::new();
- while let Some((key, value)) = map.next_entry::<String, serde_yaml::Value>()? {
+ while let Some((key, value)) = map.next_entry::<String, toml::Value>()? {
match key.as_str() {
#match_assignments
_ => {
- unused.insert(serde_yaml::Value::String(key), value);
+ unused.insert(key, value);
},
}
}
#flatten
+ // Warn about unused keys.
+ for key in unused.keys() {
+ log::warn!(target: #LOG_TARGET, "Unused config key: {}", key);
+ }
+
Ok(config)
}
}
@@ -109,7 +114,12 @@ fn field_deserializer(field_streams: &mut FieldStreams, field: &Field) -> Result
match serde::Deserialize::deserialize(value) {
Ok(value) => config.#ident = value,
Err(err) => {
- log::error!(target: #LOG_TARGET, "Config error: {}: {}", #literal, err);
+ log::error!(
+ target: #LOG_TARGET,
+ "Config error: {}: {}",
+ #literal,
+ err.to_string().trim(),
+ );
},
}
};
@@ -133,8 +143,10 @@ fn field_deserializer(field_streams: &mut FieldStreams, field: &Field) -> Result
// Create the tokens to deserialize the flattened struct from the unused fields.
field_streams.flatten.extend(quote! {
- let unused = serde_yaml::Value::Mapping(unused);
- config.#ident = serde::Deserialize::deserialize(unused).unwrap_or_default();
+ // Drain unused fields since they will be used for flattening.
+ let flattened = std::mem::replace(&mut unused, toml::Table::new());
+
+ config.#ident = serde::Deserialize::deserialize(flattened).unwrap_or_default();
});
},
"deprecated" | "removed" => {
diff --git a/alacritty_config_derive/src/serde_replace.rs b/alacritty_config_derive/src/serde_replace.rs
index 4a0a6a99..7ca5ca7c 100644
--- a/alacritty_config_derive/src/serde_replace.rs
+++ b/alacritty_config_derive/src/serde_replace.rs
@@ -28,7 +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: serde_yaml::Value) -> Result<(), Box<dyn std::error::Error>> {
+ 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());
@@ -53,7 +53,7 @@ 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: serde_yaml::Value) -> Result<(), Box<dyn std::error::Error>> {
+ 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(());