From af6f31c13c337e78c62be9f40a2ebb580e61cb28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jan=20Niemier?= Date: Wed, 13 Jan 2016 23:11:02 +0100 Subject: [PATCH] Add `FromStr` implementation for `Oid` This will allow `Oid` parsing with `str::parse`. --- src/oid.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/oid.rs b/src/oid.rs index ce3cf85bd8..a5e2897df7 100644 --- a/src/oid.rs +++ b/src/oid.rs @@ -81,6 +81,18 @@ impl fmt::Display for Oid { } } +impl str::FromStr for Oid { + type Err = Error; + + /// Parse a hex-formatted object id into an Oid structure. + /// + /// If the string is not a valid 40-character hex string, an error is + /// returned. + fn from_str(s: &str) -> Result { + Oid::from_str(s) + } +} + impl PartialEq for Oid { fn eq(&self, other: &Oid) -> bool { unsafe { raw::git_oid_equal(&self.raw, &other.raw) != 0 }