Skip to main content

FrameToken

Struct FrameToken 

Source
pub struct FrameToken { /* private fields */ }
Expand description

所有权令牌

每个令牌唯一对应一个 Frame,通过类型系统在编译期保证:

  • 不可跨线程(!Send + !Sync,通过 PhantomData<*const ()> 实现: 原始指针自动不实现 Send/Sync,令牌无法传递或共享到其他线程)
  • 不可复制/克隆(!Copy + !Clone,通过不 derive 相应 trait 实现)
  • 不可在外部构造(pub(crate) 构造函数)

§所有权守恒

令牌的生命周期必须严格遵循以下规则:

  1. 令牌创建后只能有一个所有者
  2. 所有权转移必须是原子操作
  3. 令牌销毁前必须归还到 FramePool

Implementations§

Source§

impl FrameToken

Source

pub fn frame_id(&self) -> FrameId

获取 Frame ID

Source

pub fn domain_id(&self) -> u32

获取域ID

Source

pub fn generation(&self) -> u64

获取代际号

Source

pub fn epoch(&self) -> u64

获取Epoch编号

Source

pub fn verify_ownership( &self, expected_domain: u32, expected_generation: u64, ) -> Result<(), CoreError>

验证令牌是否属于指定域和代际

使用恒定时间比较防止时序侧信道攻击。

§Arguments
  • expected_domain - 期望的域ID
  • expected_generation - 期望的代际号
§Returns
  • Ok(()) - 验证通过
  • Err(CoreError::OwnershipViolation) - 验证失败
Source

pub fn verify_epoch(&self, expected_epoch: u64) -> Result<(), CoreError>

验证令牌是否属于指定Epoch

使用恒定时间比较防止时序侧信道攻击。

§Arguments
  • expected_epoch - 期望的Epoch编号
§Returns
  • Ok(()) - 验证通过
  • Err(CoreError::StateConflict) - 验证失败
Source

pub fn into_frame_id(self) -> FrameId

消费令牌并获取 Frame ID

此方法消费令牌,返回 Frame ID。 令牌被消费后不可再使用(self 在函数结束时自动释放所有权)。

§Returns

Frame ID

Trait Implementations§

Source§

impl Debug for FrameToken

Source§

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

Formats the value using the given formatter. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more