library: core: color: add deserialization

This commit is contained in:
Bruno BELANYI 2020-03-18 13:03:02 +01:00
parent 22b109212c
commit 0644d453b8

View file

@ -1,8 +1,21 @@
use derive_more::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign, Sum};
use serde::Deserialize;
use std::ops::{Div, DivAssign, Mul, MulAssign};
#[derive(
Debug, Clone, PartialEq, Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign, Sum,
Debug,
Clone,
PartialEq,
Add,
AddAssign,
Div,
DivAssign,
Mul,
MulAssign,
Sub,
SubAssign,
Sum,
Deserialize,
)]
/// A structure to represent operations in the linear RGB colorspace.
pub struct LinearColor {
@ -285,4 +298,18 @@ mod test {
}
);
}
#[test]
fn deserialization_works() {
let yaml = "{r: 1.0, g: 0.5, b: 0.2}";
let ans: LinearColor = serde_yaml::from_str(yaml).unwrap();
assert_eq!(
ans,
LinearColor {
r: 1.0,
g: 0.5,
b: 0.2
}
)
}
}