Skip to main content

Accessor

Struct Accessor 

Source
pub struct Accessor<'db, T> { /* private fields */ }
Expand description

A user of the double buffer. There can only ever be exactly two Accessors associated with one initialized double buffer. The accessor is exclusively associated to one of the two buffers, and can obtain access using the Accessor::read or Accessor::write methods.

§Thread Safety

Accessor is Send, so you can safely send them to another thread (which is one of the primary driving use cases for a double buffer).

Note that currently, Accessor itself is not Sync.

Implementations§

Source§

impl<'db, T> Accessor<'db, T>

Source

pub fn write<'ac>(&'ac self) -> WriteGuard<'ac, 'db, T>

Accesses the current associated buffer for writing. The accessor is active as long as the returned guard exists.

Note that it is strongly advised to actually write to the buffer at least once. This is because the double buffer is marked dirty (ready to be swapped) as soon as this method is called. This means that if you call this method but do not write a value, upon release of the WriteGuard, the buffers will be swapped, and the reader will get an old value.

§Panics:

If the accessor is already active. There can only be one guard; you must drop the old one before calling read or write again.

Source

pub fn read<'ac>(&'ac self) -> ReadGuard<'ac, 'db, T>

Accesses the current associated buffer for reading. The accessor is active as long as the returned guard exists.

§Panics:

If the accessor is already active. There can only be one guard; you must drop the old one before calling read or write again.

Auto Trait Implementations§

§

impl<'db, T> !Freeze for Accessor<'db, T>

§

impl<'db, T> !RefUnwindSafe for Accessor<'db, T>

§

impl<'db, T> Send for Accessor<'db, T>

§

impl<'db, T> !Sync for Accessor<'db, T>

§

impl<'db, T> Unpin for Accessor<'db, T>

§

impl<'db, T> UnsafeUnpin for Accessor<'db, T>

§

impl<'db, T> !UnwindSafe for Accessor<'db, 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> 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.