library: serialize: add vector_normalizer helper

This commit is contained in:
Bruno BELANYI 2020-03-18 14:31:33 +01:00
parent a90d4d9405
commit 76db818fa8
2 changed files with 12 additions and 0 deletions

View file

@ -0,0 +1,2 @@
pub mod vector;
pub use vector::*;

10
src/serialize/vector.rs Normal file
View file

@ -0,0 +1,10 @@
use crate::Vector;
use serde::de::{Deserialize, Deserializer};
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())
}