Module index_ext::mem [−][src]
Expand description
Integer wrappers that are constrained to the range of usize
or isize
.
This module defines a number of wrappers around the basic integer types which ensure that the
stored value can be trivially converted to a usize
without loss of data. That is these types
offer a getter that converts the number with as usize
but otherwise they are ABI compatible
with their underlying integer type.
Usage
These are best used in places where the ABI or layout of the type is important but there is a
security risk associated with having to write (fallible) conversions all the time. Consider the
case of a matrix where dimensions are stored as u32
for compatibility reasons. We would now
like to allocate a buffer for it which requires calculating the number of elements as a u64
and then convert to usize
. However, no matter in which number type you intend to store the
result you lose semantic meaning because there is no ‘proof’ attached to the value that it will
also fit into the other value range.
use index_ext::mem::Umem64; struct Matrix { width: u32, height: u32, } let elements = u64::from(mat.width) * u64::from(mat.height); let length: Umem64 = Umem64::new(elements)?; let matrix = vec![0; length.get()];
Structs
An i8 that is also in the value range of an isize.
An i16 that is also in the value range of an isize.
An i32 that is also in the value range of an isize.
An i64 that is also in the value range of an isize.
An isize that is also in the value range of a usize.
An i8 that is also in the value range of a usize.
An i16 that is also in the value range of a usize.
An i32 that is also in the value range of a usize.
An i64 that is also in the value range of a usize.
A usize that is also in the value range of an isize.
A u8 that is also in the value range of an isize.
A u16 that is also in the value range of an isize.
A u32 that is also in the value range of an isize.
A u64 that is also in the value range of an isize.
A u8 that is also in the value range of a usize.
A u16 that is also in the value range of a usize.
A u32 that is also in the value range of a usize.
A u64 that is also in the value range of a usize.