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 = -128i8

Source§

const MAX: i8 = 127i8

Source§

const IS_SIGNED: bool = true

Source§

const BITS: u32 = 8u32

Source§

impl FixedBits for i16

Source§

const MIN: i16 = -32_768i16

Source§

const MAX: i16 = 32_767i16

Source§

const IS_SIGNED: bool = true

Source§

const BITS: u32 = 16u32

Source§

impl FixedBits for i32

Source§

const MIN: i32 = -2_147_483_648i32

Source§

const MAX: i32 = 2_147_483_647i32

Source§

const IS_SIGNED: bool = true

Source§

const BITS: u32 = 32u32

Source§

impl FixedBits for i64

Source§

const MIN: i64 = -9_223_372_036_854_775_808i64

Source§

const MAX: i64 = 9_223_372_036_854_775_807i64

Source§

const IS_SIGNED: bool = true

Source§

const BITS: u32 = 64u32

Source§

impl FixedBits for i128

Source§

const MIN: i128 = -170_141_183_460_469_231_731_687_303_715_884_105_728i128

Source§

const MAX: i128 = 170_141_183_460_469_231_731_687_303_715_884_105_727i128

Source§

const IS_SIGNED: bool = true

Source§

const BITS: u32 = 128u32

Source§

impl FixedBits for u8

Source§

const MIN: u8 = 0u8

Source§

const MAX: u8 = 255u8

Source§

const IS_SIGNED: bool = false

Source§

const BITS: u32 = 8u32

Source§

impl FixedBits for u16

Source§

const MIN: u16 = 0u16

Source§

const MAX: u16 = 65_535u16

Source§

const IS_SIGNED: bool = false

Source§

const BITS: u32 = 16u32

Source§

impl FixedBits for u32

Source§

const MIN: u32 = 0u32

Source§

const MAX: u32 = 4_294_967_295u32

Source§

const IS_SIGNED: bool = false

Source§

const BITS: u32 = 32u32

Source§

impl FixedBits for u64

Source§

const MIN: u64 = 0u64

Source§

const MAX: u64 = 18_446_744_073_709_551_615u64

Source§

const IS_SIGNED: bool = false

Source§

const BITS: u32 = 64u32

Source§

impl FixedBits for u128

Source§

const MIN: u128 = 0u128

Source§

const MAX: u128 = 340_282_366_920_938_463_463_374_607_431_768_211_455u128

Source§

const IS_SIGNED: bool = false

Source§

const BITS: u32 = 128u32

Implementors§