From aa3cc9be4974566ef52c7d820db418fcd658df2d Mon Sep 17 00:00:00 2001 From: Tyrone Tudehope Date: Wed, 3 Apr 2024 20:49:55 +0200 Subject: [PATCH] fix: Add global path qualifiers to paths used in macros; Resolves #1 --- strong_id/src/lib.rs | 19 ++++++++++--------- strong_id_macros/src/lib.rs | 6 +++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/strong_id/src/lib.rs b/strong_id/src/lib.rs index 4f67d0f..98f9692 100644 --- a/strong_id/src/lib.rs +++ b/strong_id/src/lib.rs @@ -268,20 +268,21 @@ pub trait StrongUuid { macro_rules! impl_strong_uint { ($t:ty) => { impl Id for $t { - fn encode(&self) -> String { + fn encode(&self) -> ::std::string::String { let mut out = [0u8; encoded_len::<$t>()]; - base32::encode(&self.to_be_bytes(), &mut out); + ::strong_id::base32::encode(&self.to_be_bytes(), &mut out); let encoded = unsafe { ::core::str::from_utf8_unchecked(&out) }; - format!("{encoded}") + encoded.to_string() } - fn decode>(val: T) -> Result { + fn decode>(val: T) -> ::core::result::Result { let val = val.as_ref(); if val.len() != encoded_len::<$t>() { - return Err(Error::InvalidLength(encoded_len::<$t>(), val.len())); + return Err(::strong_id::Error::InvalidLength(encoded_len::<$t>(), val.len())); } - let mut out = [0; core::mem::size_of::<$t>()]; - base32::decode(val.as_bytes(), &mut out)?; + + let mut out = [0; ::core::mem::size_of::<$t>()]; + ::strong_id::base32::decode(val.as_bytes(), &mut out)?; Ok(Self::from_be_bytes(out)) } @@ -302,7 +303,7 @@ impl Id for Uuid { let mut out = [0; 26]; base32::encode(self.as_bytes(), &mut out); let encoded = unsafe { core::str::from_utf8_unchecked(&out) }; - format!("{encoded}") + encoded.to_string() } fn decode>(val: T) -> Result { @@ -470,7 +471,7 @@ macro_rules! _internal_impl_from_str { type Err = $crate::Error; #[inline] - fn from_str(value: &str) -> Result { + fn from_str(value: &str) -> ::core::result::Result { let split = value.rsplit_once('_'); #[allow(unused_mut)] diff --git a/strong_id_macros/src/lib.rs b/strong_id_macros/src/lib.rs index 3941ff3..72cf7e7 100644 --- a/strong_id_macros/src/lib.rs +++ b/strong_id_macros/src/lib.rs @@ -104,7 +104,7 @@ pub fn derive_strong_id(input: proc_macro::TokenStream) -> proc_macro::TokenStre let serde = if cfg!(feature = "serde") { quote! { impl ::strong_id::serde::Serialize for #name { - fn serialize(&self, serializer: S) -> Result + fn serialize(&self, serializer: S) -> ::core::result::Result where S: ::strong_id::serde::Serializer, { @@ -113,11 +113,11 @@ pub fn derive_strong_id(input: proc_macro::TokenStream) -> proc_macro::TokenStre } impl<'de> ::strong_id::serde::Deserialize<'de> for #name { - fn deserialize(deserializer: D) -> Result + fn deserialize(deserializer: D) -> ::core::result::Result where D: ::strong_id::serde::Deserializer<'de>, { - String::deserialize(deserializer)? + ::std::string::String::deserialize(deserializer)? .parse::() .map_err(|error| ::strong_id::serde::de::Error::custom(error.to_string())) }