pub unsafe trait Capacity: Copy + Debug + Eq + Hash + Ord {
const MAX_REPRESENTABLE: usize;
fn from_usize(i: usize) -> Self;
fn as_usize(&self) -> usize;
}
Expand description
Types that can be used for indexing into array-like data structures.
Safety
Implementors must ensure that Capacity::from_usize(i).as_usize() == i
for
all values i <= MAX_REPRESENTABLE
. Otherwise, this expression must panic
or evaluate to false
.
Using index_type!
should be preferred over implementing this manually.
Associated Constants
const MAX_REPRESENTABLE: usize
const MAX_REPRESENTABLE: usize
The maximum usize
value that can safely be represented by this type.
Required methods
fn from_usize(i: usize) -> Self
fn from_usize(i: usize) -> Self
Convert a usize
into Self
.