pub struct GridWriter<R: GridRow> { /* private fields */ }Expand description
Writes rows into a GridStore from any thread.
Operations are applied in order by the store’s ingest task. Writing is a
short lock and a non-blocking wake-up; it never waits for the UI.
Operations written one by one may be published in different snapshots;
GridWriter::batch publishes several in one.
Implementations§
Source§impl<R: GridRow> GridWriter<R>
impl<R: GridRow> GridWriter<R>
Sourcepub fn batch(&self, write: impl FnOnce(&mut WriteBatch<R>))
pub fn batch(&self, write: impl FnOnce(&mut WriteBatch<R>))
Writes the operations of write as one batch: the store applies them
in order and publishes them in one snapshot, so no snapshot has some
of them without the others. Other writes may share that snapshot.
Nothing is written until write returns; then the batch costs one
lock and at most one wake-up.
A running reload buffers the batch’s writes until it finishes, as it
buffers single ones, but not the batch’s progress, which is never
buffered. WriteBatch::finish_reload finishes a reload inside the
batch: the reloaded rows and the batch’s writes after it, such as
clearing the progress, are published together.
writer.batch(|batch| {
batch.finish_reload(reload, rows);
batch.set_progress(None);
});Sourcepub fn begin_reload(&self) -> Reload<R>
pub fn begin_reload(&self) -> Reload<R>
Starts a reload: until Reload::finish, operations from every
writer are buffered instead of applied. finish(snapshot) hands the
snapshot and the buffered operations to the store’s ReloadPolicy
(by default the snapshot replaces every row and the buffered operations
are replayed on top). Dropping the guard without finish cancels the
reload and applies the buffered operations as usual. A newer reload
supersedes an older one: the older finish is then ignored.
Sourcepub fn upsert(&self, row: impl Into<Arc<R>>)
pub fn upsert(&self, row: impl Into<Arc<R>>)
Inserts or replaces a row by key and highlights the changed columns,
each with its GridRow::change_direction.
A new row that changes no column is published all the same, without
highlight, so hooks that read other data of the row see it. Writing
the same Arc again changes nothing.
Sourcepub fn upsert_silent(&self, row: impl Into<Arc<R>>)
pub fn upsert_silent(&self, row: impl Into<Arc<R>>)
Inserts or replaces a row by key without highlight.
Sourcepub fn mark_changed(&self, key: R::Key, columns: ColumnSet)
pub fn mark_changed(&self, key: R::Key, columns: ColumnSet)
Highlights columns of an existing row without replacing it, without a direction: the values did not change.
Sourcepub fn remove(&self, key: R::Key)
pub fn remove(&self, key: R::Key)
Removes a row by key. With a removal fade
(HighlightPolicy::with_removal_fade), its last version stays in
snapshots as a fading row (StoreSnapshot::fading_row) until the
fade ends or the key is written again.
Sourcepub fn replace_all(&self, rows: impl IntoIterator<Item = Arc<R>>)
pub fn replace_all(&self, rows: impl IntoIterator<Item = Arc<R>>)
Atomically replaces every row, without highlight.
Sourcepub fn set_pinned_rows(
&self,
edge: PinnedEdge,
rows: impl IntoIterator<Item = Arc<R>>,
)
pub fn set_pinned_rows( &self, edge: PinnedEdge, rows: impl IntoIterator<Item = Arc<R>>, )
Replaces the rows pinned at edge (an empty rows clears the band).
Applied in order with other writes; buffered by a running reload like
them. Rows are diffed by key against the previous band: changed
columns are highlighted and a new key flashes, except on the first
fill of an empty band. A key repeated within rows keeps its last
row. Pinned keys are a space of their own, apart from the data rows
and the other band. replace_all and clear leave bands alone.
Sourcepub fn set_progress(&self, progress: Option<GridProgress>)
pub fn set_progress(&self, progress: Option<GridProgress>)
Shows (Some) or clears (None) the store’s progress.
Applied in order with other writes, but never buffered by a reload:
progress written during a reload shows while the reload runs, and
progress cleared after Reload::finish is never cleared before the
snapshot that applies the reload. It may be cleared in a later one;
to clear it in that very snapshot, write both in one
GridWriter::batch with WriteBatch::finish_reload.
Sourcepub fn flush(&self) -> impl Future<Output = Option<u64>> + Send + 'static
pub fn flush(&self) -> impl Future<Output = Option<u64>> + Send + 'static
Resolves once every operation written before the call is applied and
published: with that store version (the version of the published
snapshot that has them), or None if the store is gone.
The operations waited for are fixed by the call, not by the first
poll. Operations buffered by an unfinished reload are not waited for:
they are not written to the store until Reload::finish. Each call
wakes the ingest task once; an idle store resolves with its current
version.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Returns true once the store is gone; producers can stop writing.
Sourcepub fn snapshot(&self) -> Arc<StoreSnapshot<R>>
pub fn snapshot(&self) -> Arc<StoreSnapshot<R>>
The latest published snapshot, for producers that need the current rows (e.g. to patch a row by key). Operations still queued are not in it.
Trait Implementations§
Auto Trait Implementations§
impl<R> Freeze for GridWriter<R>
impl<R> !RefUnwindSafe for GridWriter<R>
impl<R> Send for GridWriter<R>
impl<R> Sync for GridWriter<R>
impl<R> Unpin for GridWriter<R>
impl<R> UnsafeUnpin for GridWriter<R>
impl<R> !UnwindSafe for GridWriter<R>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more