Home

Isize

Isize is a primitive signed integer type in the Rust programming language. Its width is determined by the target platform’s pointer size, commonly 32 bits on 32‑bit targets and 64 bits on 64‑bit targets. Consequently, isize uses the same number of bits as a pointer on the target architecture. The range is the standard signed range for that width: isize::MIN to isize::MAX, corresponding to -(2^(N-1)) to 2^(N-1) - 1.

Isize is the signed counterpart to usize, the unsigned pointer-sized integer type. It is typically used for

In practice, isize can be used for arithmetic that may produce negative results, for example when computing

Related types include usize (the unsigned, pointer-sized counterpart) and, in C interop, the similarly named ssize_t

calculations
that
involve
offsets,
pointer
arithmetic,
or
interfaces
with
C
code
that
provide
or
expect
signed
offsets.
It
is
not
the
preferred
choice
for
indexing
collections,
where
usize
is
generally
used,
since
indexing
requires
nonnegative
indices.
differences
between
pointers
or
relative
offsets
in
certain
algorithms.
It
can
also
appear
in
FFI
boundaries
where
a
signed
offset
is
meaningful.
Developers
should
be
mindful
when
converting
between
isize
and
unsigned
types;
casting
a
negative
isize
to
a
usize
with
as
will
wrap
around
to
a
large
positive
value.
For
fallible
conversions,
explicit
checks
or
TryFrom
can
be
used
to
prevent
unintended
wraparound.
type.
Isize,
usize,
and
their
behavior
with
architecture-dependent
widths
are
central
to
writing
portable,
low-level
code
that
interacts
with
memory
layouts
and
system
interfaces.