From 3693392ee966938c966eb4c7b4c08a5ac00eabd3 Mon Sep 17 00:00:00 2001 From: Jasmine Tai Date: Mon, 1 Jul 2024 10:34:43 -0700 Subject: [PATCH 1/2] Add TryFrom impls for Ulid --- src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index bf5e868..58f568d 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,22 @@ impl FromStr for Ulid { } } +impl TryFrom<&'_ str> for Ulid { + type Error = DecodeError; + + fn try_from(value: &'_ str) -> Result { + Ulid::from_string(value) + } +} + +impl TryFrom for Ulid { + type Error = DecodeError; + + fn try_from(value: String) -> 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]; From 55415b21ec5fe51f68c303945daf6d75b2b4fac1 Mon Sep 17 00:00:00 2001 From: Jasmine Tai Date: Sat, 13 Jul 2024 14:38:16 -0700 Subject: [PATCH 2/2] Remove unneeded impl TryFrom for Ulid --- src/lib.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 58f568d..aafebdf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -365,14 +365,6 @@ impl TryFrom<&'_ str> for Ulid { } } -impl TryFrom for Ulid { - type Error = DecodeError; - - fn try_from(value: String) -> 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];