Skip to main content

IntWidth

Enum IntWidth 

Source
pub enum IntWidth {
    I8,
    U8,
    I16,
    U16,
    I32,
    U32,
    U64,
}
Expand description

Integer width types with real width semantics.

Does NOT include i64 — that stays as the default int type.

Variants§

§

I8

§

U8

§

I16

§

U16

§

I32

§

U32

§

U64

Implementations§

Source§

impl IntWidth

Source

pub const ALL: [IntWidth; 7]

All 7 width variants.

Source

pub const fn bits(self) -> u32

Number of bits in this width.

Source

pub const fn is_signed(self) -> bool

Whether this is a signed integer type.

Source

pub const fn is_unsigned(self) -> bool

Whether this is an unsigned integer type.

Source

pub const fn mask(self) -> u64

Bit mask for the value range (e.g., 0xFF for 8-bit).

Source

pub const fn sign_shift(self) -> u32

Bit position of the sign bit (e.g., 7 for i8).

Source

pub const fn min_value(self) -> i64

Minimum value representable as i64. For unsigned types, this is 0.

Source

pub const fn max_value(self) -> i64

Maximum value representable as i64. For U64, this returns i64::MAX (the max signed portion).

Source

pub const fn max_unsigned(self) -> u64

Maximum value representable as u64 (meaningful for unsigned types).

Source

pub const fn type_name(self) -> &'static str

Human-readable type name (e.g., “i8”, “u64”).

Source

pub const fn truncate(self, value: i64) -> i64

Canonical truncation: wraps an i64 value to this width using two’s complement semantics.

For signed types: mask then sign-extend. For U64: identity (no truncation needed for i64→u64 bit reinterpret). For other unsigned: just mask.

Source

pub const fn truncate_u64(self, value: u64) -> u64

Unsigned-safe truncation: wraps a u64 value to this width.

For signed types: mask then sign-extend (returned as u64 bit pattern). For unsigned types: just mask.

Source

pub fn from_name(name: &str) -> Option<IntWidth>

Parse a width name (e.g., “i8”, “u64”) to an IntWidth.

Source§

impl IntWidth

Source

pub fn join(a: IntWidth, b: IntWidth) -> Result<IntWidth, ()>

Join two widths for mixed-width arithmetic.

Rules:

  • Same width → Ok(same)
  • Different widths, same signedness → Ok(wider)
  • Mixed sign: u8+i8→I16, u16+i16→I32, u32+i32→I64 (widen to next signed)
  • u64 + any signed → Err(()) (compile error — no safe widening)
Source

pub const fn in_range_i64(self, value: i64) -> bool

Check if a given i64 value is in range for this width.

Source

pub const fn in_range_u64(self, value: u64) -> bool

Check if a given u64 value is in range for this width.

Trait Implementations§

Source§

impl Clone for IntWidth

Source§

fn clone(&self) -> IntWidth

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for IntWidth

Source§

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

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

impl<'de> Deserialize<'de> for IntWidth

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for IntWidth

Source§

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

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

impl Hash for IntWidth

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 IntWidth

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for IntWidth

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for IntWidth

Source§

impl Eq for IntWidth

Source§

impl StructuralPartialEq for IntWidth

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,