Skip to main content

IntegerInfo

Struct IntegerInfo 

Source
pub struct IntegerInfo {
    pub signed: bool,
    pub width: u32,
}
Expand description

What an integer type is once it no longer matters how it was spelled.

A width and a signedness, which between them are everything the value of an integer constant depends on. int, an enumeration represented in int, and _BitInt(32) are three different types with one IntegerInfo, and every question about what a constant of any of them holds has the same answer for all three.

The width is the value’s and not the object’s. bool is one bit here and one byte in layout, and _BitInt(37) is thirty seven bits here and eight bytes there.

Fields§

§signed: bool

Whether the type can hold a negative value.

§width: u32

How many bits of a value the type keeps.

Implementations§

Source§

impl IntegerInfo

Source

pub const fn new(signed: bool, width: u32) -> IntegerInfo

An integer type of the given signedness and width.

Source

pub const fn wrap(self, raw: i128) -> i128

The value raw becomes once it is stored in a type of this shape.

The low width bits of it, extended into the rest by the signedness. That is the form a folded constant is held in, so 300 wrapped by a char is 44, -1 wrapped by an unsigned int is 4294967295, and a value of a hundred and twenty eight bit type is itself, because there is nothing wider left to extend it into.

Source

pub const fn holds(self, raw: i128) -> bool

Whether raw is a value a type of this shape can hold.

Every hundred and twenty eight bit pattern is a value of a hundred and twenty eight bit type, of either signedness, which is why this is a question about the width rather than a comparison against a pair of bounds: unsigned __int128 has a greatest value that no i128 can be handed to ask about.

Trait Implementations§

Source§

impl Clone for IntegerInfo

Source§

fn clone(&self) -> IntegerInfo

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for IntegerInfo

Source§

impl Debug for IntegerInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for IntegerInfo

Source§

impl Hash for IntegerInfo

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for IntegerInfo

Source§

fn eq(&self, other: &IntegerInfo) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for IntegerInfo

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.