pub struct Reader<R: Resource> { /* private fields */ }Expand description
The current state of one resource over one live document, kept up to date
incrementally: each sync applies only what changed since
the last one (Resource::refresh), and demand reads
the parts views look at (Resource::load).
The framework keeps one per open resource; a custom surface running outside the framework (a standalone test harness) can keep its own.
Implementations§
Source§impl<R: Resource> Reader<R>
impl<R: Resource> Reader<R>
Sourcepub fn open(doc: &mut Doc) -> Result<Self, ModelError>
pub fn open(doc: &mut Doc) -> Result<Self, ModelError>
Read the resource from doc and start following its changes.
A reader reads for views: a #[model(demanded)] field is read only
in the items a view demands (Self::demand), and a change to an
item reads what it touched in it. Self::read_all reads every
field.
Sourcepub fn read(doc: &Doc) -> Result<Self, ModelError>
pub fn read(doc: &Doc) -> Result<Self, ModelError>
Read the resource from a document that may only be read, and follow
its changes from the next sync on.
Sourcepub fn read_all(doc: &Doc) -> Result<Self, ModelError>
pub fn read_all(doc: &Doc) -> Result<Self, ModelError>
Self::read, reading every field as stored, the
#[model(demanded)] ones too, now and at every sync: what search
derives from a resource whose views read less of it.
Sourcepub fn with_state(state: R::State, heads: Option<Vec<ChangeHash>>) -> Self
pub fn with_state(state: R::State, heads: Option<Vec<ChangeHash>>) -> Self
Follow a document from a state already read from it at heads
(None when unknown: the first sync reads everything again).
Sourcepub fn state(&self) -> &Rc<R::State>
pub fn state(&self) -> &Rc<R::State>
The current state. Cheap: shares the value.
Holding the returned Rc across the next sync keeps
what it shows unchanged: that sync brings a copy up to date instead
(Resource::copy_state). The copy shares what the change did not
touch: every Collection item, the items of each
Keyed or Ordered field (a
touched one is copied once), and the chunks of each
Map, Set and Grid.
Plain fields (a Vec, a BTreeMap) are copied whole: a large one
belongs in one of those, and a view that needs only part of a state
keeps that part rather than the Rc.
Sourcepub fn last_delta(&self) -> &Delta
pub fn last_delta(&self) -> &Delta
What the last sync that changed the state applied: the parts of the
document it touched, or Delta::everything when it read the state
whole (an open transaction, a failed refresh, the first read).
Sourcepub fn unreadable(&self) -> Option<&Unreadable>
pub fn unreadable(&self) -> Option<&Unreadable>
Why the document does not read as the resource since the last sync, if it does not: the state is then the last one that did read, and a view shows this instead of it.
Sourcepub fn revision(&self) -> u64
pub fn revision(&self) -> u64
Increases whenever what the state says changes: the document moved,
or the state is presented again. Reading more of the same document
(Self::demand) is not a new revision.
Sourcepub fn loads(&self) -> u64
pub fn loads(&self) -> u64
Increases whenever a demand read parts of the document the state did
not hold yet (Self::demand).
Sourcepub fn follows(&self, doc: &Doc) -> bool
pub fn follows(&self, doc: &Doc) -> bool
Whether the state is doc as it stands: no change arrived since the
last sync.
Sourcepub fn leads_to(&self, doc: &Doc) -> bool
pub fn leads_to(&self, doc: &Doc) -> bool
Whether doc holds every change of the last sync, so syncing to it
applies what moved since (Tracker::leads_to).
Sourcepub fn replace(&mut self, state: R::State)
pub fn replace(&mut self, state: R::State)
Take state as the resource’s state now, read elsewhere than from
a document this reader follows (a settings section, as the settings
document holds it): a new revision, in which everything changed.
Sourcepub fn represent(&mut self)
pub fn represent(&mut self)
Count the unchanged state as a new revision, so everything following it takes it again (a surface dropping an optimistic preview).
Sourcepub fn current_demand(&self) -> &Demand
pub fn current_demand(&self) -> &Demand
What views currently demand.
Sourcepub fn sync(&mut self, doc: &Doc) -> Result<bool, ModelError>
pub fn sync(&mut self, doc: &Doc) -> Result<bool, ModelError>
Apply whatever changed in doc since the last sync. Returns whether
the state changed.
§Errors
Returns ModelError when the document no longer holds this
resource; the state is left as it was last read successfully and the
next sync reads it whole.
Sourcepub fn demand(&mut self, doc: &Doc, demand: Demand) -> Result<bool, ModelError>
pub fn demand(&mut self, doc: &Doc, demand: Demand) -> Result<bool, ModelError>
Ask for the parts demand names (replacing the previous demand) and
read those not read yet. Returns whether the state changed.
Sourcepub fn reread_whole(&mut self, doc: &Doc) -> Result<bool, ModelError>
pub fn reread_whole(&mut self, doc: &Doc) -> Result<bool, ModelError>
Read the state whole from doc, whatever the last sync saw move: so a
change this reader could not apply as a delta is reported
(Self::unreadable) rather than passed over, which a resource kept
small enough to read whole can afford on every sync. Returns whether
the state changed.
§Errors
Returns ModelError when the document no longer holds this
resource; the state is left as it was last read successfully.
Auto Trait Implementations§
impl<R> !Send for Reader<R>
impl<R> !Sync for Reader<R>
impl<R> Forget for Reader<R>
impl<R> Freeze for Reader<R>
impl<R> Move for Reader<R>
impl<R> RefUnwindSafe for Reader<R>
impl<R> Unpin for Reader<R>
impl<R> UnsafeUnpin for Reader<R>
impl<R> UnwindSafe for Reader<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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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