chiark
/
gitweb
/
~ianmdlvl
/
otter.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
1fb6b1b
)
materials format: Provide try_from_integer
author
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Wed, 4 May 2022 21:55:50 +0000
(22:55 +0100)
committer
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Wed, 4 May 2022 22:00:10 +0000
(23:00 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/materials-format.rs
patch
|
blob
|
history
diff --git
a/src/materials-format.rs
b/src/materials-format.rs
index 9bdf634c7f8183f127cd9408101223d511ba0261..223f0ad677e1af016b52cd3d229842a8a1bf7e15 100644
(file)
--- a/
src/materials-format.rs
+++ b/
src/materials-format.rs
@@
-49,6
+49,15
@@
impl TryFrom<Raw> for Version {
}
}
+impl Version {
+ #[throws(VersionError)]
+ pub fn try_from_integer<I>(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)]