Struct Cell

Source
pub struct Cell<A> {
    pub impl_: Cell<A>,
}
Expand description

Represents a value of type A that changes over time.

In other Functional Reactive Programming (FRP) systems this is also called a behavior, property, or a signal. A Cell should be used for modeling any pieces of mutable state in an FRP application.

Fields§

§impl_: Cell<A>

Implementations§

Source§

impl<A: Clone + Send + 'static> Cell<A>

Source

pub fn new(sodium_ctx: &SodiumCtx, value: A) -> Cell<A>

Create a Cell with a constant value.

Source

pub fn sample(&self) -> A

Sample the Cell’s current value.

Cell::sample may be used in the functions passed to primitives that apply them to Streams, including Stream::map, Stream::snapshot, Stream::filter, and Stream::merge.

When called within a function passed to Stream::map using sample is equivalent to snapshotting this Cell with that Stream.

Source

pub fn sample_lazy(&self) -> Lazy<A>

Sample the Cell’s current value lazily.

When it is necessary to use sample while implementing more general abstractions, sample_lazy should be preferred in case a CellLoop is passed rather than a Cell.

See Cell::sample for more details.

Source

pub fn updates(&self) -> Stream<A>

Return a Stream that gives the updates/steps for a Cell.

§Important

This is an operational primitive, which isn’t part of the main Sodium API. It breaks the property of non-detectability of cell updates/steps. The rule with this primitive is that you should only use it in functions that don’t allow the caller to detect the Cell updates.

Source

pub fn value(&self) -> Stream<A>

Return a Stream that is guaranteed to fire at least once.

When value is called, the returned Stream will fire once in the current transaction with the current value of this Cell and thereafter behaves like Cell::updates.

§Important

This is an operational primitive, which isn’t part of the main Sodium API. It breaks the property of non-detectability of cell updates/steps. The rule with this primitive is that you should only use it in functions that don’t allow the caller to detect the Cell updates.

Source

pub fn map<B: Clone + Send + 'static, FN: IsLambda1<A, B> + Send + Sync + 'static>( &self, f: FN, ) -> Cell<B>

Transform the Cells value with the supplied function.

The returned Cell always reflects the value produced by the function applied to the input Cells value. The given function must be referentially transparent.

Source

pub fn lift2<B: Clone + Send + 'static, C: Clone + Send + 'static, FN: IsLambda2<A, B, C> + Send + 'static>( &self, cb: &Cell<B>, f: FN, ) -> Cell<C>

Lift a binary function into cells so the returned Cell always reflects the specified function applied to the input cells’ values.

Source

pub fn lift3<B: Clone + Send + 'static, C: Clone + Send + 'static, D: Clone + Send + 'static, FN: IsLambda3<A, B, C, D> + Send + 'static>( &self, cb: &Cell<B>, cc: &Cell<C>, f: FN, ) -> Cell<D>

Lift a ternary function into cells so the returned Cell always reflects the specified function applied to the input cells’ values.

Source

pub fn lift4<B: Clone + Send + 'static, C: Clone + Send + 'static, D: Clone + Send + 'static, E: Clone + Send + 'static, FN: IsLambda4<A, B, C, D, E> + Send + 'static>( &self, cb: &Cell<B>, cc: &Cell<C>, cd: &Cell<D>, f: FN, ) -> Cell<E>

Lift a quaternary function into cells so the returned Cell always reflects the specified function applied to the input cells’ values.

Source

pub fn lift5<B: Clone + Send + 'static, C: Clone + Send + 'static, D: Clone + Send + 'static, E: Clone + Send + 'static, F: Clone + Send + 'static, FN: IsLambda5<A, B, C, D, E, F> + Send + 'static>( &self, cb: &Cell<B>, cc: &Cell<C>, cd: &Cell<D>, ce: &Cell<E>, f: FN, ) -> Cell<F>

Lift a five-argument function into cells so the returned Cell always reflects the specified function applied to the input cells’ values.

Source

pub fn lift6<B: Clone + Send + 'static, C: Clone + Send + 'static, D: Clone + Send + 'static, E: Clone + Send + 'static, F: Clone + Send + 'static, G: Clone + Send + 'static, FN: IsLambda6<A, B, C, D, E, F, G> + Send + 'static>( &self, cb: &Cell<B>, cc: &Cell<C>, cd: &Cell<D>, ce: &Cell<E>, cf: &Cell<F>, f: FN, ) -> Cell<G>

Lift a six argument function into cells so the returned Cell always reflects the specified function applied to the input cells’ values.

Source

pub fn switch_s(csa: &Cell<Stream<A>>) -> Stream<A>

Unwrap a Stream in a Cell to give a time-varying stream implementation.

Source

pub fn switch_c(cca: &Cell<Cell<A>>) -> Cell<A>

Unwrap a Cell in another Cell to give a time-varying cell implementation.

Source

pub fn listen_weak<K: FnMut(&A) + Send + Sync + 'static>( &self, k: K, ) -> Listener

A variant of listen that will deregister the listener automatically if the listener is garbage-collected.

Source

pub fn listen<K: IsLambda1<A, ()> + Send + Sync + 'static>( &self, k: K, ) -> Listener

Listen for updates to the value of this Cell.

This is the observer pattern. The returned Listener has an unlisten method to cause the listener to be removed.

This is an operational mechanism for interfacing between the world of I/O and FRP.

Trait Implementations§

Source§

impl<A> Clone for Cell<A>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<A> Freeze for Cell<A>

§

impl<A> !RefUnwindSafe for Cell<A>

§

impl<A> Send for Cell<A>
where A: Send,

§

impl<A> Sync for Cell<A>
where A: Send,

§

impl<A> Unpin for Cell<A>

§

impl<A> !UnwindSafe for Cell<A>

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