pub trait Bits {
type Type;
fn bits() -> Self::Type;
}
macro_rules! ImplementBits {
($type:ty) => {
impl Bits for $type {
type Type = $type;
fn bits() -> Self::Type {
Self::BITS as Self::Type
}
}
};
}
ImplementBits!(u8);
ImplementBits!(u32);
ImplementBits!(u64);
#[cfg(test)]
mod tests {
use super::Bits;
#[test]
fn test_bits() {
assert_eq!(u8::bits(), 8);
assert_eq!(u32::bits(), 32);
assert_eq!(u64::bits(), 64);
}
}