pub struct FrameToken { /* private fields */ }Expand description
所有权令牌
每个令牌唯一对应一个 Frame,通过类型系统在编译期保证:
- 不可跨线程(!Send + !Sync,通过
PhantomData<*const ()>实现: 原始指针自动不实现 Send/Sync,令牌无法传递或共享到其他线程) - 不可复制/克隆(!Copy + !Clone,通过不 derive 相应 trait 实现)
- 不可在外部构造(
pub(crate)构造函数)
§所有权守恒
令牌的生命周期必须严格遵循以下规则:
- 令牌创建后只能有一个所有者
- 所有权转移必须是原子操作
- 令牌销毁前必须归还到 FramePool
Implementations§
Source§impl FrameToken
impl FrameToken
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
获取代际号
Sourcepub fn verify_ownership(
&self,
expected_domain: u32,
expected_generation: u64,
) -> Result<(), CoreError>
pub fn verify_ownership( &self, expected_domain: u32, expected_generation: u64, ) -> Result<(), CoreError>
Sourcepub fn into_frame_id(self) -> FrameId
pub fn into_frame_id(self) -> FrameId
Trait Implementations§
Auto Trait Implementations§
impl !Send for FrameToken
impl !Sync for FrameToken
impl Freeze for FrameToken
impl RefUnwindSafe for FrameToken
impl Unpin for FrameToken
impl UnsafeUnpin for FrameToken
impl UnwindSafe for FrameToken
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