
The impl_for
macro is used 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(T = "i8")]
#[impl_for(T = "u8")]
#[impl_for(T = "i16")]
#[impl_for(T = "u16")]
#[impl_for(T = "i32")]
#[impl_for(T = "u32")]
#[impl_for(T = "i64")]
#[impl_for(T = "u64")]
#[impl_for(T = "isize")]
#[impl_for(T = "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()
}
}