1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2025-08-07 22:12:25 -04:00

Replace serde's derive with custom proc macro

This replaces the existing `Deserialize` derive from serde with a
`ConfigDeserialize` derive. The goal of this new proc macro is to allow
a more error-friendly deserialization for the Alacritty configuration
file without having to manage a lot of boilerplate code inside the
configuration modules.

The first part of the derive macro is for struct deserialization. This
takes structs which have `Default` implemented and will only replace
fields which can be successfully deserialized. Otherwise the `log` crate
is used for printing errors. Since this deserialization takes the
default value from the struct instead of the value, it removes the
necessity for creating new types just to implement `Default` on them for
deserialization.

Additionally, the struct deserialization also checks for `Option` values
and makes sure that explicitly specifying `none` as text literal is
allowed for all options.

The other part of the derive macro is responsible for deserializing
enums. While only enums with Unit variants are supported, it will
automatically implement a deserializer for these enums which accepts any
form of capitalization.

Since this custom derive prevents us from using serde's attributes on
fields, some of the attributes have been reimplemented for
`ConfigDeserialize`. These include `#[config(flatten)]`,
`#[config(skip)]` and `#[config(alias = "alias)]`. The flatten attribute
is currently limited to at most one per struct.

Additionally the `#[config(deprecated = "optional message")]` attribute
allows easily defining uniform deprecation messages for fields on
structs.
This commit is contained in:
Christian Duerr 2020-12-21 02:44:38 +00:00 committed by GitHub
parent 37a3198d88
commit 6e1b9d8b25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 1046 additions and 1057 deletions

View file

@ -2,6 +2,7 @@
members = [
"alacritty",
"alacritty_terminal",
"alacritty_config_derive",
]
[profile.release]