diff --git a/src/lib.rs b/src/lib.rs index bf5e868..aafebdf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,6 +49,7 @@ mod time_utils; #[cfg(feature = "uuid")] mod uuid; +use core::convert::TryFrom; use core::fmt; use core::str::FromStr; @@ -356,6 +357,14 @@ impl FromStr for Ulid { } } +impl TryFrom<&'_ str> for Ulid { + type Error = DecodeError; + + fn try_from(value: &'_ str) -> Result { + 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];