pub trait UnsignedInteger: Numeric {
type Signed: SignedInteger<Unsigned = Self>;
const MSB_BIT: Self;
const LSB_BIT: Self;
const ALL: Self;
// Required methods
fn as_non_negative(self) -> Self::Signed;
fn as_negative(self, bits: u32) -> Self::Signed;
fn as_negative_fixed<const BITS: u32>(self) -> Self::Signed;
fn checked_shl(self, rhs: u32) -> Option<Self>;
fn checked_shr(self, rhs: u32) -> Option<Self>;
// Provided methods
fn shl_default(self, rhs: u32) -> Self { ... }
fn shr_default(self, rhs: u32) -> Self { ... }
}
Expand description
This trait extends many common unsigned integer types so that they can be used with the bitstream handling traits.
Required Associated Constants§
Required Associated Types§
Sourcetype Signed: SignedInteger<Unsigned = Self>
type Signed: SignedInteger<Unsigned = Self>
The signed variant of ourself
Required Methods§
Sourcefn as_non_negative(self) -> Self::Signed
fn as_non_negative(self) -> Self::Signed
Given a twos-complement value, return this value is a non-negative signed number. The location of the sign bit depends on the stream’s endianness and is not stored in the result.
§Example
use bitstream_io::UnsignedInteger;
assert_eq!(0b00000001u8.as_non_negative(), 1i8);
Sourcefn as_negative(self, bits: u32) -> Self::Signed
fn as_negative(self, bits: u32) -> Self::Signed
Given a two-complement positive value and certain number of bits, returns this value as a negative signed number. The location of the sign bit depends on the stream’s endianness and is not stored in the result.
§Example
use bitstream_io::UnsignedInteger;
assert_eq!(0b01111111u8.as_negative(8), -1i8);
Sourcefn as_negative_fixed<const BITS: u32>(self) -> Self::Signed
fn as_negative_fixed<const BITS: u32>(self) -> Self::Signed
Given a two-complement positive value and certain number of bits, returns this value as a negative number.
§Example
use bitstream_io::UnsignedInteger;
assert_eq!(0b01111111u8.as_negative_fixed::<8>(), -1i8);
Sourcefn checked_shl(self, rhs: u32) -> Option<Self>
fn checked_shl(self, rhs: u32) -> Option<Self>
Checked shift left
Sourcefn checked_shr(self, rhs: u32) -> Option<Self>
fn checked_shr(self, rhs: u32) -> Option<Self>
Checked shift right
Provided Methods§
Sourcefn shl_default(self, rhs: u32) -> Self
fn shl_default(self, rhs: u32) -> Self
Shift left up to our length in bits
If rhs equals our length in bits, returns default
Sourcefn shr_default(self, rhs: u32) -> Self
fn shr_default(self, rhs: u32) -> Self
Shift left up to our length in bits
If rhs equals our length in bits, returns zero
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.