Allow deriving Serialize and Deserialize on generated refinement (#3227)

This PR adds support for deriving `Serialize` and `Deserialize` on the
refinement type generated by `#[derive(Refineable)]`.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2023-11-03 22:21:00 +01:00 committed by GitHub
parent edacffab58
commit 287ea0a6e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 4 deletions

View file

@ -49,7 +49,7 @@ pub struct GitStatusColors {
}
#[derive(Refineable, Clone, Debug)]
#[refineable(debug)]
#[refineable(debug, deserialize)]
pub struct ThemeColors {
pub border: Hsla,
pub border_variant: Hsla,
@ -105,6 +105,8 @@ pub struct ThemeStyles {
#[cfg(test)]
mod tests {
use serde_json::json;
use super::*;
#[test]
@ -146,4 +148,16 @@ mod tests {
assert_eq!(colors.text, magenta);
assert_eq!(colors.background, green);
}
#[test]
fn deserialize_theme_colors_refinement_from_json() {
let colors: ThemeColorsRefinement = serde_json::from_value(json!({
"background": "#ff00ff",
"text": "#ff0000"
}))
.unwrap();
assert_eq!(colors.background, Some(gpui::rgb(0xff00ff)));
assert_eq!(colors.text, Some(gpui::rgb(0xff0000)));
}
}