Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TryFrom impls for Ulid #82

Merged
merged 2 commits into from
Jul 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
j-tai marked this conversation as resolved.
Show resolved Hide resolved
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
Loading