Skip to content

Commit

Permalink
Add TryFrom impls for Ulid
Browse files Browse the repository at this point in the history
  • Loading branch information
j-tai committed Jul 1, 2024
1 parent a3c1073 commit 3693392
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 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,22 @@ 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 TryFrom<String> for Ulid {
type Error = DecodeError;

fn try_from(value: String) -> 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 3693392

Please sign in to comment.