Skip to content

Commit

Permalink
Merge pull request #82 from j-tai/try-from
Browse files Browse the repository at this point in the history
Add TryFrom impls for Ulid
  • Loading branch information
dylanhart authored Jul 13, 2024
2 parents a3c1073 + 55415b2 commit dbd58a3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ mod time_utils;
#[cfg(feature = "uuid")]
mod uuid;

use core::convert::TryFrom;
use core::fmt;
use core::str::FromStr;

Expand Down Expand Up @@ -356,6 +357,14 @@ impl FromStr for Ulid {
}
}

impl TryFrom<&'_ str> for Ulid {
type Error = DecodeError;

fn try_from(value: &'_ str) -> Result<Self, Self::Error> {
Ulid::from_string(value)
}
}

impl fmt::Display for Ulid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
let mut buffer = [0; ULID_LEN];
Expand Down

0 comments on commit dbd58a3

Please sign in to comment.