pub struct VecExtent { /* private fields */ }Expand description
A validated Vec length: a non-negative item count the runtime can actually
allocate.
The third of ADR-041 decision 1’s validated newtypes, beside GridExtent
and BitIndex, and it exists for the same reason they do: Vec(n, fill)
(ADR-146) takes a user-supplied Int to a vec![fill; n], so n = -1 would
cast to usize::MAX and ask the host for 147 exabytes — an OOM abort raised
inside an extern "C" function, which the program that caused it never gets
to see. praxis_vec_filled cannot reach the allocation without one of these,
so the guard is not something a caller can forget.
Implementations§
Source§impl VecExtent
impl VecExtent
Sourcepub const MAX_ITEMS: usize = GridExtent::MAX_CELLS
pub const MAX_ITEMS: usize = GridExtent::MAX_CELLS
The longest Vec the runtime will construct at a stroke: 2^28 items,
which is GridExtent::MAX_CELLS and is 2 GiB of GcRef storage before
a single element object exists.
The same number as a grid’s for the same reason ADR-041 decision 2 gave:
a cell of one and an item of the other are the same eight bytes, and a
count that merely fits in a usize is still an allocation no host can
serve. push is not bounded by this and does not need to be — it grows
one item at a time, so there is no single multiplication to overflow.