pub struct Version(/* private fields */);Expand description
Represents the version of a slot, combining generation and state.
The lowest 2 bits represent the state:
- 0b00: Vacant
- 0b01: Reserved
- 0b10: Retired (the maximum generation was exhausted)
- 0b11: Occupied
The upper 30 bits represent the generation.
表示 slot 的版本,结合了代数(generation)和状态。
最低 2 位表示状态:
- 0b00: 空闲 (Vacant)
- 0b01: 预留 (Reserved)
- 0b10: 退休 (Retired,最大代数已耗尽)
- 0b11: 占用 (Occupied)
高 30 位表示代数。
Implementations§
Source§impl Version
impl Version
Sourcepub const fn new(generation: Generation, state: u32) -> Option<Self>
pub const fn new(generation: Generation, state: u32) -> Option<Self>
Create a new Version with specified generation and state
使用指定的代数和状态创建一个新 Version
Returns None for an invalid state or when the retired state is used
with a generation other than Generation::MAX.
Sourcepub fn generation(&self) -> Generation
pub fn generation(&self) -> Generation
Get the generation part
获取代数部分
Sourcepub fn is_reserved(&self) -> bool
pub fn is_reserved(&self) -> bool
Check if logic state is Reserved (0b01)
检查逻辑状态是否为预留 (0b01)
Sourcepub fn is_occupied(&self) -> bool
pub fn is_occupied(&self) -> bool
Check if logic state is Occupied (0b11)
检查逻辑状态是否被占用 (0b11)
Sourcepub fn is_retired(&self) -> bool
pub fn is_retired(&self) -> bool
Check if the slot has exhausted its generation counter and can never be reused.
Trait Implementations§
impl Copy for Version
impl Eq for Version
impl StructuralPartialEq for Version
Auto Trait Implementations§
impl Freeze for Version
impl RefUnwindSafe for Version
impl Send for Version
impl Sync for Version
impl Unpin for Version
impl UnsafeUnpin for Version
impl UnwindSafe for Version
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more