Skip to main content

Version

Struct Version 

Source
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
  • 0b11: Occupied

The upper 30 bits represent the generation.

表示 slot 的版本,结合了代数(generation)和状态。

最低 2 位表示状态:

  • 0b00: 空闲 (Vacant)
  • 0b01: 预留 (Reserved)
  • 0b11: 占用 (Occupied)

高 30 位表示代数。

Implementations§

Source§

impl Version

Source

pub fn new(generation: Generation, state: u32) -> Self

Create a new Version with specified generation and state

使用指定的代数和状态创建一个新 Version

Source

pub fn sentinel() -> Self

Create a sentinel version

创建哨兵版本

Source

pub fn generation(&self) -> Generation

Get the generation part

获取代数部分

Source

pub fn state(&self) -> u32

Get the state part (lowest 2 bits)

获取状态部分(最低 2 位)

Source

pub fn is_vacant(&self) -> bool

Check if logic state is Vacant (0b00)

检查逻辑状态是否为空闲 (0b00)

Source

pub fn is_reserved(&self) -> bool

Check if logic state is Reserved (0b01)

检查逻辑状态是否为预留 (0b01)

Source

pub fn is_occupied(&self) -> bool

Check if logic state is Occupied (0b11)

检查逻辑状态是否被占用 (0b11)

Source

pub fn vacant_to_reserved(&mut self)

Transition: Vacant -> Reserved

Increases value by 1 (0bXX00 -> 0bXX01)

状态转换:空闲 -> 预留

值增加 1 (0bXX00 -> 0bXX01)

Source

pub fn reserved_to_occupied(&mut self)

Transition: Reserved -> Occupied

Increases value by 2 (0bXX01 -> 0bXX11)

状态转换:预留 -> 占用

值增加 2 (0bXX01 -> 0bXX11)

Source

pub fn occupied_to_vacant(&mut self)

Transition: Occupied -> Vacant (Next Generation)

Increases value by 1 (0bXX11 -> 0bYY00), handles generation wrap

状态转换:占用 -> 空闲(下一代)

值增加 1 (0bXX11 -> 0bYY00),处理代数回绕

Source

pub fn reserved_to_vacant(&mut self)

Transition: Reserved -> Vacant (Next Generation)

Used when releasing a handle. Increases value by 3 (0bXX01 -> 0bYY00), handles generation wrap

状态转换:预留 -> 空闲(下一代)

用于释放 handle 时。 值增加 3 (0bXX01 -> 0bYY00),处理代数回绕

Trait Implementations§

Source§

impl Clone for Version

Source§

fn clone(&self) -> Version

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Version

Source§

impl Debug for Version

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Version

Source§

impl PartialEq for Version

Source§

fn eq(&self, other: &Version) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Version

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.