Skip to main content
isize is a signed integer type in Rust whose bit width is statically determined at compile time by the pointer size of the target architecture. It occupies 16 bits on 16-bit systems, 32 bits on 32-bit systems, and 64 bits on 64-bit systems, ensuring its memory footprint exactly matches that of a machine pointer.

Memory Layout and Architecture Dependency

The size of isize is intrinsically linked to the target’s address space. It is the signed counterpart to usize and utilizes two’s complement representation for negative values. Because it is a Sized type, its dimensions are known at compile time and never evaluated dynamically at runtime.

Value Range

Because isize is architecture-dependent, its minimum and maximum bounds vary based on the compilation target. On 16-bit architectures (e.g., avr, msp430):
  • Minimum: -2^15 (-32,768)
  • Maximum: 2^15 - 1 (32,767)
On 32-bit architectures (e.g., i686, armv7):
  • Minimum: -2^31 (-2,147,483,648)
  • Maximum: 2^31 - 1 (2,147,483,647)
On 64-bit architectures (e.g., x86_64, aarch64):
  • Minimum: -2^63 (-9,223,372,036,854,775,808)
  • Maximum: 2^63 - 1 (9,223,372,036,854,775,807)
These boundaries are exposed as associated constants in the standard library:

Type Casting and Safety

Due to its variable bit width, casting between isize and fixed-width integer types (like i32 or i64) carries architecture-specific truncation or sign-extension semantics. Using the as keyword forces a cast. While casting primitive integers with as is completely safe and never results in undefined behavior (it has strictly defined two’s complement truncation or sign-extension semantics), it can cause logical bugs via silent data loss if the value exceeds the target type’s capacity:
To prevent silent data loss, Rust implements the TryFrom and TryInto traits for isize. These evaluate the runtime validity of the cast based on the compiled architecture and return a Result, ensuring that out-of-bounds conversions are explicitly handled rather than silently truncated.
Tired of Poor Rust Skills? Fix That With Deep Grasping!Learn More