Skip to content

Commit

Permalink
fix: Add global path qualifiers to paths used in macros; Resolves #1
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnynotsolucky committed Apr 3, 2024
1 parent 701fa67 commit aa3cc9b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
19 changes: 10 additions & 9 deletions strong_id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: AsRef<str>>(val: T) -> Result<Self, Error> {
fn decode<T: AsRef<str>>(val: T) -> ::core::result::Result<Self, ::strong_id::Error> {
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))
}
Expand All @@ -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<T: AsRef<str>>(val: T) -> Result<Self, Error> {
Expand Down Expand Up @@ -470,7 +471,7 @@ macro_rules! _internal_impl_from_str {
type Err = $crate::Error;

#[inline]
fn from_str(value: &str) -> Result<Self, Self::Err> {
fn from_str(value: &str) -> ::core::result::Result<Self, Self::Err> {
let split = value.rsplit_once('_');

#[allow(unused_mut)]
Expand Down
6 changes: 3 additions & 3 deletions strong_id_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
fn serialize<S>(&self, serializer: S) -> ::core::result::Result<S::Ok, S::Error>
where
S: ::strong_id::serde::Serializer,
{
Expand All @@ -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<D>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D>(deserializer: D) -> ::core::result::Result<Self, D::Error>
where
D: ::strong_id::serde::Deserializer<'de>,
{
String::deserialize(deserializer)?
::std::string::String::deserialize(deserializer)?
.parse::<Self>()
.map_err(|error| ::strong_id::serde::de::Error::custom(error.to_string()))
}
Expand Down

0 comments on commit aa3cc9b

Please sign in to comment.