From eff133abf3750d44d290a85fb6c45ec2f6858f29 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 18 Mar 2020 14:38:26 +0100 Subject: [PATCH] library: texture: uniform: add deserialization --- src/texture/uniform.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/texture/uniform.rs b/src/texture/uniform.rs index a6e1bda..02492eb 100644 --- a/src/texture/uniform.rs +++ b/src/texture/uniform.rs @@ -1,9 +1,10 @@ use super::Texture; use crate::core::LinearColor; use crate::Point2D; +use serde::Deserialize; /// A texture with the same color on all points. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Deserialize)] pub struct UniformTexture { color: LinearColor, } @@ -34,6 +35,7 @@ mod test { fn simple_texture() -> UniformTexture { UniformTexture::new(LinearColor::new(0.25, 0.5, 1.)) } + #[test] fn texel_color_works() { let texture = simple_texture(); @@ -42,4 +44,16 @@ mod test { LinearColor::new(0.25, 0.5, 1.) ) } + + #[test] + fn deserialization_works() { + let yaml = r#" + color: {r: 1.0, g: 0.5, b: 0.25} + "#; + let texture: UniformTexture = serde_yaml::from_str(yaml).unwrap(); + assert_eq!( + texture, + UniformTexture::new(LinearColor::new(1., 0.5, 0.25)) + ) + } }