SwmrCell

Struct SwmrCell 

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

A single-writer, multi-reader cell with version-based garbage collection.

SwmrCell provides safe concurrent access where one writer can update the value and multiple readers can read it concurrently. Readers access the value by creating a LocalReader and pinning it.

单写多读单元,带有基于版本的垃圾回收。

SwmrCell 提供安全的并发访问,其中一个写入者可以更新值, 多个读者可以并发读取它。读者通过创建 LocalReader 并 pin 来访问值。

Implementations§

Source§

impl<T: 'static> SwmrCell<T>

Source

pub fn new(data: T) -> Self

Create a new SWMR cell with default settings and the given initial value.

使用默认设置和给定的初始值创建一个新的 SWMR 单元。

Source

pub fn builder() -> SwmrCellBuilder<T>

Returns a builder for configuring the SWMR cell.

返回用于配置 SWMR 单元的构建器。

Source

pub fn local(&self) -> LocalReader<T>

Create a new LocalReader for reading.

Each thread should create its own LocalReader and reuse it. LocalReader is !Sync and should not be shared between threads.

创建一个新的 LocalReader 用于读取。 每个线程应该创建自己的 LocalReader 并重复使用。 LocalReader!Sync 的,不应在线程之间共享。

Source

pub fn store(&mut self, data: T)

Store a new value, making it visible to readers. The old value is retired and will be garbage collected.

This operation increments the global version.

存储新值,使其对读者可见。 旧值已退休,将被垃圾回收。 此操作会增加全局版本。

Source

pub fn collect(&mut self)

Manually trigger garbage collection. 手动触发垃圾回收。

Auto Trait Implementations§

§

impl<T> Freeze for SwmrCell<T>

§

impl<T> RefUnwindSafe for SwmrCell<T>
where T: RefUnwindSafe,

§

impl<T> Send for SwmrCell<T>
where T: Send,

§

impl<T> Sync for SwmrCell<T>
where T: Sync,

§

impl<T> Unpin for SwmrCell<T>

§

impl<T> UnwindSafe for SwmrCell<T>
where T: UnwindSafe,

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> 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, 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.