pathtracer/src/serialize/vector.rs
2020-03-23 12:42:36 +01:00

16 lines
435 B
Rust

//! Helper functions to deserialize `Vector` values.
use crate::Vector;
use serde::de::{Deserialize, Deserializer};
/// Deserialize a vector.
///
/// Needs a custom implementation to make sur the vector is normalized when deserialized.
pub fn vector_normalizer<'de, D>(deserializer: D) -> Result<Vector, D::Error>
where
D: Deserializer<'de>,
{
let v: Vector = Deserialize::deserialize(deserializer)?;
Ok(v.normalize())
}