pathtracer/src/serialize/vector.rs

16 lines
435 B
Rust
Raw Normal View History

2020-03-22 00:29:24 +01:00
//! Helper functions to deserialize `Vector` values.
use crate::Vector;
use serde::de::{Deserialize, Deserializer};
2020-03-22 00:29:24 +01:00
/// 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())
}