Skip to content

Commit

Permalink
Add FromStr implementation for Oid
Browse files Browse the repository at this point in the history
This will allow `Oid` parsing with `str::parse`.
  • Loading branch information
hauleth committed Jan 13, 2016
1 parent f3d5633 commit af6f31c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, Error> {
Oid::from_str(s)
}
}

impl PartialEq for Oid {
fn eq(&self, other: &Oid) -> bool {
unsafe { raw::git_oid_equal(&self.raw, &other.raw) != 0 }
Expand Down

0 comments on commit af6f31c

Please sign in to comment.