From dea673e5442ffe0a0ec151e5a4be2ab8b48a3a5d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 4 May 2022 22:55:50 +0100 Subject: [PATCH] materials format: Provide try_from_integer Signed-off-by: Ian Jackson --- src/materials-format.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/materials-format.rs b/src/materials-format.rs index 9bdf634c..223f0ad6 100644 --- a/src/materials-format.rs +++ b/src/materials-format.rs @@ -49,6 +49,15 @@ impl TryFrom for Version { } } +impl Version { + #[throws(VersionError)] + pub fn try_from_integer(i: I) -> Version + where I: num::Integer + ToPrimitive { + let v = i.to_u32().ok_or_else(|| MFVE::Other("integer out of range"))?; + v.try_into()? + } +} + impl FromStr for Version { type Err = VersionError; #[throws(VersionError)] -- 2.30.2