chiark / gitweb /
materials format: String parsing
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 4 May 2022 21:52:24 +0000 (22:52 +0100)
committerIan 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

index 84abe90bf0e7721bb086e093669a0225361a8635..9bdf634c7f8183f127cd9408101223d511ba0261 100644 (file)
@@ -49,6 +49,16 @@ impl TryFrom<Raw> for Version {
   }
 }
 
+impl FromStr for Version {
+  type Err = VersionError;
+  #[throws(VersionError)]
+  fn from_str(s: &str) -> Version {
+    let v: Raw = s.parse()
+      .map_err(|_| MFVE::Other("could not parse as ingeger"))?;
+    v.try_into()?
+  }
+}
+
 macro_rules! impl_compar_i32 { {
   $(
     impl $Trait:ident { fn $method:ident -> $out:ty; }