PinGuard

Struct PinGuard 

Source
pub struct PinGuard<'a, T: 'static> { /* private fields */ }
Expand description

A guard that keeps the current thread pinned to a version.

PinGuard is obtained by calling LocalReader::pin(). It implements Deref<Target = T> to allow reading the current value. It is !Send and !Sync because it references a !Sync LocalReader. Its lifetime is bound to the LocalReader it came from.

While a PinGuard is held, the thread is considered “active” at a particular version, and the garbage collector will not reclaim data from that version.

PinGuard supports internal cloning via reference counting (increments the pin count), allowing nested pinning. The thread remains pinned until all cloned guards are dropped.

Safety: The PinGuard is the mechanism that ensures safe concurrent access to shared values. Readers must always hold a valid PinGuard when accessing shared data.

一个保持当前线程被钉住到一个版本的守卫。 PinGuard 通过调用 LocalReader::pin() 获得。 它实现了 Deref<Target = T>,允许读取当前值。 它是 !Send!Sync 的,因为它引用了一个 !SyncLocalReader。 它的生命周期被绑定到它来自的 LocalReader。 当 PinGuard 被持有时,线程被认为在特定版本“活跃“, 垃圾回收器不会回收该版本的数据。 PinGuard 支持通过引用计数的内部克隆(增加 pin 计数),允许嵌套 pinning。 线程保持被钉住直到所有克隆的守卫被 drop。 安全性PinGuard 是确保对值安全并发访问的机制。 读者在访问共享数据时必须始终持有有效的 PinGuard

Implementations§

Source§

impl<T: 'static> PinGuard<'_, T>

Source

pub fn version(&self) -> usize

Get the version that this guard is pinned to.

获取此守卫被 pin 到的版本。

Trait Implementations§

Source§

impl<T: 'static> AsRef<T> for PinGuard<'_, T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a, T> Clone for PinGuard<'a, T>

Source§

fn clone(&self) -> Self

Clone this guard to create a nested pin.

Cloning increments the pin count, and the thread remains pinned until all cloned guards are dropped. This allows multiple scopes to hold pins simultaneously.

克隆此守卫以创建嵌套 pin。

克隆会增加 pin 计数,线程保持被钉住直到所有克隆的守卫被 drop。 这允许多个作用域同时持有 pin。

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + 'static> Debug for PinGuard<'_, T>

Source§

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

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

impl<'a, T> Deref for PinGuard<'a, T>

Source§

fn deref(&self) -> &T

Dereference to access the pinned value.

Returns a reference to the value that was current when this guard was created. This provides snapshot semantics - the value won’t change during the guard’s lifetime.

解引用以访问被 pin 的值。

返回对创建此守卫时当前值的引用。 这提供了快照语义 - 在守卫的生命周期内值不会改变。

Source§

type Target = T

The resulting type after dereferencing.
Source§

impl<'a, T> Drop for PinGuard<'a, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for PinGuard<'a, T>

§

impl<'a, T> !RefUnwindSafe for PinGuard<'a, T>

§

impl<'a, T> !Send for PinGuard<'a, T>

§

impl<'a, T> !Sync for PinGuard<'a, T>

§

impl<'a, T> Unpin for PinGuard<'a, T>

§

impl<'a, T> !UnwindSafe for PinGuard<'a, T>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.