From 92c3a1f0c6bbe5354d4e5eca0d6dab570482f26b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 26 Feb 2021 22:30:50 +0000 Subject: [PATCH] utils: Provide PosC::from_iter Signed-off-by: Ian Jackson --- src/spec.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/spec.rs b/src/spec.rs index c8d0e8eb..e1f7f9a6 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -321,6 +321,20 @@ pub mod pos_traits { impl PosC { pub fn promote(&self) -> PosC { self.map(|v| v as f64) } } + + #[derive(Error,Debug,Copy,Clone,Serialize,Deserialize)] + pub struct PosCFromIteratorError; + display_as_debug!{PosCFromIteratorError} + + impl PosC { + #[throws(PosCFromIteratorError)] + pub fn from_iter>(i: I) -> Self { PosC( + i + .collect::>() + .into_inner() + .map_err(|_| PosCFromIteratorError)? + )} + } } //---------- Implementation ---------- -- 2.30.2