Skip to main content

LiveView

Struct LiveView 

Source
pub struct LiveView<T> { /* private fields */ }
Expand description

A query’s rows, the row of a one() query, or the value of an aggregate, read as its Rust type and kept current, from Zero::live (LiveQuery in the Swift client, useQuery in zero-react).

Each update of the view is read into the value, reading only the rows whose entries changed. When the client replaces itself, the view moves to the new client, and the live view with it. Dropping it removes its listeners and destroys the view; the server keeps syncing the query for its TTL.

Implementations§

Source§

impl<T: 'static> LiveView<T>

Source

pub fn value(&self) -> Rc<T>

The value last read. Holding it past the next update makes that update read every row again rather than only those that changed.

Source

pub fn result_type(&self) -> ResultType

Whether the server has confirmed the rows on this connection (Complete) or an earlier one (Cached), or not yet (Unknown), or the query failed (Error).

Source

pub fn error(&self) -> Option<LiveError>

Why the server could not run the query, or why the rows could not be read as T, which keeps the value last read.

Source

pub fn view(&self) -> &MaterializedView

The view the value is read from.

Source

pub fn update_ttl(&self, ttl: &Ttl)

Raises the query’s TTL; a lower one is ignored.

Source

pub fn add_listener( &self, listener: impl Fn(&T, ResultType) + 'static, ) -> Box<dyn Fn()>

Calls listener with the value and result type now, and after every update of the view, once the value is read. After a read that failed, it gets the value kept, and error says why. Returns the function that removes it.

Trait Implementations§

Source§

impl<T> Drop for LiveView<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for LiveView<T>

§

impl<T> !Send for LiveView<T>

§

impl<T> !Sync for LiveView<T>

§

impl<T> !UnwindSafe for LiveView<T>

§

impl<T> Forget for LiveView<T>

§

impl<T> Freeze for LiveView<T>
where Rc<Inner<T>>: Freeze,

§

impl<T> Move for LiveView<T>

§

impl<T> Unpin for LiveView<T>
where Rc<Inner<T>>: Unpin,

§

impl<T> UnsafeUnpin for LiveView<T>
where Rc<Inner<T>>: UnsafeUnpin,

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