impl-for

Crates.ioimpl-for
lib.rsimpl-for
version0.2.1
sourcesrc
created_at2024-05-21 07:33:47.925077
updated_at2024-05-23 01:29:05.854578
descriptionMacros to impl for multiple types
homepage
repositoryhttps://github.com/Bajix/impl-for/
max_upload_size
id1246492
size8,133
Thomas Sieverding (Bajix)

documentation

README

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()
    }
}
Commit count: 10

cargo fmt