Skip to main content

Reader

Struct Reader 

Source
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>

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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

Source

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.

Source

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.

Source

pub fn loads(&self) -> u64

Increases whenever a demand read parts of the document the state did not hold yet (Self::demand).

Source

pub fn follows(&self, doc: &Doc) -> bool

Whether the state is doc as it stands: no change arrived since the last sync.

Source

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

Source

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.

Source

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

Source

pub fn current_demand(&self) -> &Demand

What views currently demand.

Source

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.

Source

pub fn demand(&mut self, doc: &Doc, demand: Demand) -> Result<bool, ModelError>
where R::State: Clone,

Ask for the parts demand names (replacing the previous demand) and read those not read yet. Returns whether the state changed.

Source

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>
where Rc<<R as Resource>::State>: Freeze,

§

impl<R> Move for Reader<R>

§

impl<R> RefUnwindSafe for Reader<R>
where Rc<<R as Resource>::State>: RefUnwindSafe,

§

impl<R> Unpin for Reader<R>
where Rc<<R as Resource>::State>: Unpin,

§

impl<R> UnsafeUnpin for Reader<R>
where Rc<<R as Resource>::State>: UnsafeUnpin,

§

impl<R> UnwindSafe for Reader<R>
where Rc<<R as Resource>::State>: 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more