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>
impl<'db, T> Accessor<'db, T>
Sourcepub fn write<'ac>(&'ac self) -> WriteGuard<'ac, 'db, T>
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.
Sourcepub fn read<'ac>(&'ac self) -> ReadGuard<'ac, 'db, T>
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.