pub struct LotId(/* private fields */);
Expand description
A LotId
is a single usize
, encoding generation information in the top
1/4 of the bits, and index information in the remaining bits. This table
shows the breakdown for supported target platforms:
target_pointer_width | generation bits | index bits |
---|---|---|
16 | 4 | 12 |
32 | 8 | 24 |
64 | 16 | 48 |
Each time a lot is allocated, its generation is incremented. When retrieving
values using a LotId
, the generation is validated as a safe guard against
returning a value. Because the generation isn’t significantly wide, the
generation can wrap and is not a perfect protection against stale data,
although the likelihood of improper access is greatly reduced.
Implementations§
source§impl LotId
impl LotId
sourcepub const fn as_bytes(self) -> [u8; 8]
pub const fn as_bytes(self) -> [u8; 8]
Returns this ID as bytes. To decode the resulting bytes, use
from_bytes()
.
The result of this fuction changes size based on the width of usize
.
sourcepub fn from_bytes(bytes: &[u8]) -> Option<Self>
pub fn from_bytes(bytes: &[u8]) -> Option<Self>
Decodes bytes
that were previously encoded with
as_bytes()
and returns a LotId
if it appears to be
a valid ID.
This function will “upgrade” previously encoded LotId
s from
architectures where usize
is smaller than the current architecture.
Trait Implementations§
source§impl<T> Index<LotId> for OrderedLots<T>
impl<T> Index<LotId> for OrderedLots<T>
source§impl<T> IndexMut<LotId> for OrderedLots<T>
impl<T> IndexMut<LotId> for OrderedLots<T>
source§impl Ord for LotId
impl Ord for LotId
source§impl PartialEq for LotId
impl PartialEq for LotId
source§impl PartialOrd for LotId
impl PartialOrd for LotId
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more