4 releases

0.2.1 May 23, 2024
0.2.0 May 23, 2024
0.1.1 May 22, 2024
0.1.0 May 21, 2024

#1384 in Procedural macros

Download history 332/week @ 2024-05-20 5/week @ 2024-06-03 4/week @ 2024-06-10

341 downloads per month
Used in 2 crates (via into-bytes)

MIT license

9KB
115 lines

License Cargo Documentation

Macros for repeating implementations with type substitutions.

Example

Before:

macro_rules! itoa_into_bytes {
    ($t:ty) => {
        impl IntoBytes for $t {
            fn into_bytes(self) -> Vec<u8> {
                let mut buf = ::itoa::Buffer::new();
                let s = buf.format(self);
                s.as_bytes().to_vec()
            }
        }
    };
}

itoa_into_bytes!(i8);
itoa_into_bytes!(u8);
itoa_into_bytes!(i16);
itoa_into_bytes!(u16);
itoa_into_bytes!(i32);
itoa_into_bytes!(u32);
itoa_into_bytes!(i64);
itoa_into_bytes!(u64);
itoa_into_bytes!(isize);
itoa_into_bytes!(usize);

After:

#[impl_for_each(i8, u8, i16, u16, i32, u32, i64, isize, usize)]
impl IntoBytes for T {
    fn into_bytes(self) -> Vec<u8> {
        let mut buf = ::itoa::Buffer::new();
        let s = buf.format(self);
        s.as_bytes().to_vec()
    }
}

Dependencies

~0.6–1.1MB
~25K SLoC