rutil 0.2.0

A library containing utilities for creating programs in rust.
Documentation
/// Bit counting operations.
pub trait BitCountingOps {
    /// Returns the number of ones in the binary representation of `self`.
    fn count_ones(self) -> u32;

    /// Returns the number of zeros in the binary representation of `self`.
    fn count_zeros(self) -> u32;

    /// Returns the number of leading zeros in the binary representation of `self`.
    fn leading_zeros(self) -> u32;

    /// Returns the number of trailing zeros in the binary representation of `self`.
    fn trailing_zeros(self) -> u32;

    /// Returns the number of leading ones in the binary representation of `self`.
    fn leading_ones(self) -> u32;

    /// Returns the number of trailing ones in the binary representation of `self`.
    fn trailing_ones(self) -> u32;
}

/// Implements [`BitCountingOps`].
macro_rules! impl_bit_counting {
    ($($t:ty),*) => {
        $(impl BitCountingOps for $t {
            #[inline] fn count_ones(self) -> u32 { self.count_ones() }
            #[inline] fn count_zeros(self) -> u32 { self.count_zeros() }
            #[inline] fn leading_zeros(self) -> u32 { self.leading_zeros() }
            #[inline] fn trailing_zeros(self) -> u32 { self.trailing_zeros() }
            #[inline] fn leading_ones(self) -> u32 { self.leading_ones() }
            #[inline] fn trailing_ones(self) -> u32 { self.trailing_ones() }
        })*
    };
}

impl_bit_counting!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);