Skip to main content

ReactiveCell

Struct ReactiveCell 

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

A reactive value you can read, write and subscribe to, with the primitive behind it erased - along with its type parameters, so fields, map entries and in-memory values share one type and one collection.

Writes always reach where the value lives.

Implementations§

Source§

impl<T> ReactiveCell<T>
where T: Clone + Send + Sync + 'static,

Source

pub fn new(initial: T) -> Self

An in-memory cell, for reactive values that are not persisted.

Source

pub fn get(&self) -> T

Source

pub fn durable(&self) -> Durable<'_, Self>

The same writes, each returning only once the value is on disk.

A cell over a value held in memory has nothing to commit to, and its writes here behave as the plain ones do.

Source

pub fn set(&self, value: T) -> WriteResult<()>

Fails if the write is refused - by an interceptor, or by the store. The cache is left to the store subscription, so a refused write never shows up in get().

Source

pub fn update<F>(&self, f: F) -> WriteResult<T>
where F: FnOnce(T) -> T,

Read-modify-write, not atomic.

Source

pub fn modify<F>(&self, f: F) -> WriteResult<()>
where F: FnOnce(&mut T),

Same caveat as ReactiveCell::update: read-modify-write, not atomic.

Source

pub fn subscribe<F>(&self, callback: F) -> SignalSubscription
where F: Fn(&T) + Send + Sync + 'static,

Source

pub fn subscribe_with_source<F>(&self, callback: F) -> SignalSubscription
where F: Fn(&T, Option<Uuid>) + Send + Sync + 'static,

Subscribes with the provenance of each change, so a subscriber can tell its own writes from everyone else’s.

Source

pub fn subscription_with(&self) -> Watch<Self, Immediate>

Configures a subscription: filtering, provenance, and where the callback runs. See Watch.

Trait Implementations§

Source§

impl<T> Clone for ReactiveCell<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Clone + Send + Sync + 'static> Debug for ReactiveCell<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Reactive<T> for ReactiveCell<T>
where T: Clone + Send + Sync + 'static,

Source§

fn get(&self) -> T

Source§

fn subscribe_with_source<F>(&self, callback: F) -> SignalSubscription
where F: for<'a> Fn(&'a T, Option<Uuid>) + Send + Sync + 'static,

Source§

fn keepalive(&self) -> Option<Arc<dyn Send + Sync>>

Source§

fn subscribe<F>(&self, callback: F) -> SignalSubscription
where F: for<'a> Fn(&'a T) + Send + Sync + 'static,

Source§

impl<T> Watchable for ReactiveCell<T>
where T: Clone + Send + Sync + 'static,

Source§

type Item = T

What a subscriber is handed.
Source§

fn watch_id(&self) -> Uuid

Identity of the handle, so external can tell its own writes apart.
Source§

fn watch_raw<F>(&self, callback: F) -> SignalSubscription
where F: Fn(&T, Option<Uuid>) + Send + Sync + 'static,

Source§

fn filterable(_item: &Self::Item) -> bool

Whether Watch::external may drop this item when it came from this handle. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for ReactiveCell<T>

§

impl<T> !UnwindSafe for ReactiveCell<T>

§

impl<T> Freeze for ReactiveCell<T>

§

impl<T> Send for ReactiveCell<T>
where T: Sync + Send,

§

impl<T> Sync for ReactiveCell<T>
where T: Sync + Send,

§

impl<T> Unpin for ReactiveCell<T>

§

impl<T> UnsafeUnpin for ReactiveCell<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<R, T> IntoPipeline<T> for R
where R: Reactive<T>, T: Clone + Send + Sync + 'static,

Source§

fn pipe(self) -> Pipeline<T>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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