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§
Implementations§
Source§impl IntWidth
impl IntWidth
Sourcepub const fn is_unsigned(self) -> bool
pub const fn is_unsigned(self) -> bool
Whether this is an unsigned integer type.
Sourcepub const fn sign_shift(self) -> u32
pub const fn sign_shift(self) -> u32
Bit position of the sign bit (e.g., 7 for i8).
Sourcepub const fn min_value(self) -> i64
pub const fn min_value(self) -> i64
Minimum value representable as i64. For unsigned types, this is 0.
Sourcepub const fn max_value(self) -> i64
pub const fn max_value(self) -> i64
Maximum value representable as i64. For U64, this returns i64::MAX (the max signed portion).
Sourcepub const fn max_unsigned(self) -> u64
pub const fn max_unsigned(self) -> u64
Maximum value representable as u64 (meaningful for unsigned types).
Sourcepub const fn truncate(self, value: i64) -> i64
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.
Sourcepub const fn truncate_u64(self, value: u64) -> u64
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§impl IntWidth
impl IntWidth
Sourcepub fn join(a: IntWidth, b: IntWidth) -> Result<IntWidth, ()>
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)
Sourcepub const fn in_range_i64(self, value: i64) -> bool
pub const fn in_range_i64(self, value: i64) -> bool
Check if a given i64 value is in range for this width.
Sourcepub const fn in_range_u64(self, value: u64) -> bool
pub const fn in_range_u64(self, value: u64) -> bool
Check if a given u64 value is in range for this width.