Skip to main content

FixedBits

Trait FixedBits 

Source
pub trait FixedBits
where Self: Default + Hash + Ord + Contiguous + Pod + Debug + Display + LowerExp + UpperExp + Binary + Octal + LowerHex + UpperHex + FromStr<Err = ParseIntError> + Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign + Mul<Output = Self> + MulAssign + Div<Output = Self> + DivAssign + Rem<Output = Self> + RemAssign + Not<Output = Self> + BitAnd<Output = Self> + BitAndAssign + BitOr<Output = Self> + BitOrAssign + BitXor<Output = Self> + BitXorAssign + Shl<u32, Output = Self> + ShlAssign<u32> + Shr<u32, Output = Self> + ShrAssign<u32> + Sum + Product + FixedEquiv + FixedBitsCast<i8> + FixedBitsCast<i16> + FixedBitsCast<i32> + FixedBitsCast<i64> + FixedBitsCast<i128> + FixedBitsCast<isize> + FixedBitsCast<u8> + FixedBitsCast<u16> + FixedBitsCast<u32> + FixedBitsCast<u64> + FixedBitsCast<u128> + FixedBitsCast<usize> + FixedBitsOptionalArbitrary + FixedBitsOptionalBorsh + FixedBitsOptionalNum + FixedBitsOptionalSerde + Sealed,
{ const MIN: Self; const MAX: Self; const IS_SIGNED: bool; const BITS: u32; }
Expand description

This trait is implemented for Fixed::Bits for all fixed-point numbers.

This provides some facilities to manipulate bits in generic functions.

This trait is sealed and cannot be implemented for more types; it is implemented for i8, i16, i32, i64, i128, u8, u16, u32, u64, and u128.

§Examples

use az::OverflowingAs;
use fixed::traits::Fixed;
use fixed::types::*;
fn limited_positive_bits<F: Fixed>(fixed: F) -> Option<u32> {
    let bits = fixed.to_bits();
    match bits.overflowing_as::<u32>() {
        (wrapped, false) => Some(wrapped),
        (_, true) => None,
    }
}
assert_eq!(limited_positive_bits(I16F16::from_bits(100)), Some(100));
assert_eq!(limited_positive_bits(I16F16::from_bits(-100)), None);

Required Associated Constants§

Source

const MIN: Self

The smallest value that can be represented by this integer type.

Source

const MAX: Self

The largest value that can be represented by this integer type.

Source

const IS_SIGNED: bool

true if this integer type is signed.

Source

const BITS: u32

The size of this integer type in bits.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl FixedBits for i8

Source§

const MIN: i8 = i8::MIN

Source§

const MAX: i8 = i8::MAX

Source§

const IS_SIGNED: bool

Source§

const BITS: u32 = i8::BITS

Source§

impl FixedBits for i16

Source§

const MIN: i16 = i16::MIN

Source§

const MAX: i16 = i16::MAX

Source§

const IS_SIGNED: bool

Source§

const BITS: u32 = i16::BITS

Source§

impl FixedBits for i32

Source§

const MIN: i32 = i32::MIN

Source§

const MAX: i32 = i32::MAX

Source§

const IS_SIGNED: bool

Source§

const BITS: u32 = i32::BITS

Source§

impl FixedBits for i64

Source§

const MIN: i64 = i64::MIN

Source§

const MAX: i64 = i64::MAX

Source§

const IS_SIGNED: bool

Source§

const BITS: u32 = i64::BITS

Source§

impl FixedBits for i128

Source§

const MIN: i128 = i128::MIN

Source§

const MAX: i128 = i128::MAX

Source§

const IS_SIGNED: bool

Source§

const BITS: u32 = i128::BITS

Source§

impl FixedBits for u8

Source§

const MIN: u8 = u8::MIN

Source§

const MAX: u8 = u8::MAX

Source§

const IS_SIGNED: bool

Source§

const BITS: u32 = u8::BITS

Source§

impl FixedBits for u16

Source§

const MIN: u16 = u16::MIN

Source§

const MAX: u16 = u16::MAX

Source§

const IS_SIGNED: bool

Source§

const BITS: u32 = u16::BITS

Source§

impl FixedBits for u32

Source§

const MIN: u32 = u32::MIN

Source§

const MAX: u32 = u32::MAX

Source§

const IS_SIGNED: bool

Source§

const BITS: u32 = u32::BITS

Source§

impl FixedBits for u64

Source§

const MIN: u64 = u64::MIN

Source§

const MAX: u64 = u64::MAX

Source§

const IS_SIGNED: bool

Source§

const BITS: u32 = u64::BITS

Source§

impl FixedBits for u128

Source§

const MIN: u128 = u128::MIN

Source§

const MAX: u128 = u128::MAX

Source§

const IS_SIGNED: bool

Source§

const BITS: u32 = u128::BITS

Implementors§