From: Ian Jackson Date: Fri, 26 Feb 2021 22:30:50 +0000 (+0000) Subject: utils: Provide PosC::from_iter X-Git-Tag: otter-0.4.0~347 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=92c3a1f0c6bbe5354d4e5eca0d6dab570482f26b;p=otter.git utils: Provide PosC::from_iter Signed-off-by: Ian Jackson --- 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 ----------