Skip to content

Commit

Permalink
Forward isize/usize to other primitive implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 20, 2024
1 parent acf0029 commit cf17729
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,32 @@ impl_Integer!(u32[U32_MAX_LEN] as u32);
impl_Integer!(i64[I64_MAX_LEN] as u64);
impl_Integer!(u64[U64_MAX_LEN] as u64);

#[cfg(target_pointer_width = "16")]
impl_Integer!(isize[I16_MAX_LEN] as u16);
#[cfg(target_pointer_width = "16")]
impl_Integer!(usize[U16_MAX_LEN] as u16);

#[cfg(target_pointer_width = "32")]
impl_Integer!(isize[I32_MAX_LEN] as u32);
#[cfg(target_pointer_width = "32")]
impl_Integer!(usize[U32_MAX_LEN] as u32);

#[cfg(target_pointer_width = "64")]
impl_Integer!(isize[I64_MAX_LEN] as u64);
#[cfg(target_pointer_width = "64")]
impl_Integer!(usize[U64_MAX_LEN] as u64);
macro_rules! impl_Integer_size {
($t:ty as $primitive:ident #[cfg(target_pointer_width = $width:literal)]) => {
#[cfg(target_pointer_width = $width)]
impl Integer for $t {
const MAX_STR_LEN: usize = <$primitive as Integer>::MAX_STR_LEN;
}

#[cfg(target_pointer_width = $width)]
impl private::Sealed for $t {
type Buffer = <$primitive as private::Sealed>::Buffer;

#[inline]
#[cfg_attr(feature = "no-panic", no_panic)]
fn write(self, buf: &mut Self::Buffer) -> &str {
(self as $primitive).write(buf)
}
}
};
}

impl_Integer_size!(isize as i16 #[cfg(target_pointer_width = "16")]);
impl_Integer_size!(usize as u16 #[cfg(target_pointer_width = "16")]);
impl_Integer_size!(isize as i32 #[cfg(target_pointer_width = "32")]);
impl_Integer_size!(usize as u32 #[cfg(target_pointer_width = "32")]);
impl_Integer_size!(isize as i64 #[cfg(target_pointer_width = "64")]);
impl_Integer_size!(usize as u64 #[cfg(target_pointer_width = "64")]);

macro_rules! impl_Integer128 {
($t:ty[$max_len:expr]) => {
Expand Down

0 comments on commit cf17729

Please sign in to comment.