pub fn mask<T>(length: u8, inverted: bool)-> T
    where
        T: Integer + std::convert::From<u8> + Shl<usize, Output=T> + BitOr<Output=T> + Not<Output=T> + Debug,
{
    let mut normal_mask = T::from(0_u8);
    for _ in 0..length {
        normal_mask = (normal_mask << 1 as usize) | T::from(1_u8);
    }
    match inverted {
        true=> !normal_mask,
        false=> normal_mask,
    }
}
/// Return a mask to apply to binary operations.
///
/// # Parameters:
/// * length: Number of 1's from least significant bit. Every other bit is set to 0.
/// * inverted: If true then a number of 0's equal to length is placed from least significant bit.
/// Every other bit is set to 1.
///
/// # Returns:
/// * A mask coded in the same type that generic parameter.
///
/// # Example:
/// ```ignore
/// let mask_normal = mask::<u8>(3, false);
/// assert_eq!(mask_normal, 0b_0000_0111 as u8);
///
/// let mask_inverted = mask::<u32>(3, true);
/// assert_eq!(mask_inverted, 0b_1111_1111_1111_1111_1111_1111_1111_1000 as u32);
/// ```
Return a mask to apply to binary operations.
Return a mask to apply to binary operations .
pub fn mask<T>(length: u8, inverted: bool)-> T
    where
        T: Integer + std::convert::From<u8> + Shl<usize, Output=T> + BitOr<Output=T> + Not<Output=T> + Debug,
{
    let mut normal_mask = T::from(0_u8);
    for _ in 0..length {
        normal_mask = (normal_mask << 1 as usize) | T::from(1_u8);
    }
    match inverted {
        true=> !normal_mask,
        false=> normal_mask,
    }
}
pub fn mask < T > ( length : u8 , inverted : bool ) -> T where T : Integer + std :: convert :: From < u8 > + Shl < usize , Output = T > + BitOr < Output = T > + Not < Output = T > + Debug , { let mut normal_mask = T :: from ( 0_u8 ) ; for _ in 0 .. length { normal_mask = ( normal_mask << 1 as usize ) | T :: from ( 1_u8 ) ; } match inverted { true => ! normal_mask , false => normal_mask , } }
Return a mask to apply to binary operations.
Return a mask to apply to binary operations .
length
u8
inverted
bool
length
u8
inverted
bool
parameters:
Number of 1's from least significant bit. Every other bit is set to 0.
inverted: If true then a number of 0's equal to length is placed from least significant bit.
Every other bit is set to 1.
Number of 1 ' s from least significant bit . Every other bit is set to 0 . inverted : If true then a number of 0 ' s equal to length is placed from least significant bit . Every other bit is set to 1 .
returns:
A mask coded in the same type that generic parameter.
A mask coded in the same type that generic parameter .
example:
None