Skip to main content

Previous

Struct Previous 

Source
pub struct Previous<T: Clone + PartialEq + 'static> { /* private fields */ }
Expand description

Tracks the previously observed value of some external reactive source.

Typical use: in a render closure, call previous.record(current) at the top, then read previous.get_previous().get() to find out what the value was on the previous render. The two reads are decoupled so callers can record and read independently.

§Why a Signal<Option<T>>?

Because the very first call to record has no “previous” to report. The signal starts at None and flips to Some(value) after the first record. Render code can branch on the Option for “first render vs subsequent”.

§Lombok caveat

Previous cannot use Lombok New because the previous: Signal<Option<T>> field would require T: Default to satisfy Signal::default(). The struct intentionally keeps T: Clone + PartialEq + 'static (no Default), and the constructor is hand-written in impl.rs to wrap the field with Signal::create(None).

Implementations§

Source§

impl<T: Clone + PartialEq + 'static> Previous<T>

Inherent implementation of Previous.

Source

pub fn new() -> Self

Creates a new Previous with no recorded value. The previous signal starts at None.

Source

pub fn record(&self, current: T)

Records current as the new previous value. The next call to get_previous_snapshot() will return Some(current).

This is typically called at the top of a render closure so the signal stores the value just seen.

§Arguments
  • T: Clone + PartialEq + 'static - A generic type parameter.
Source

pub fn get_previous_snapshot(&self) -> Option<T>

Returns a snapshot of the previously recorded value, or None if no value has been recorded yet.

§Returns
  • Option<T> - The previous captured value, or None.
Source

pub fn clear(&self)

Clears the recorded previous value, returning the tracker to the None state.

Source§

impl<T: Clone + PartialEq + 'static> Previous<T>

Source

pub fn get_previous(&self) -> &Signal<Option<T>>

Source

pub fn get_mut_previous(&mut self) -> &mut Signal<Option<T>>

Source

pub fn set_previous(&mut self, val: Signal<Option<T>>) -> &mut Self

Trait Implementations§

Source§

impl<T: Clone + Clone + PartialEq + 'static> Clone for Previous<T>

Source§

fn clone(&self) -> Previous<T>

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> Copy for Previous<T>
where T: Clone + PartialEq + 'static,

Previous<T> is Copy when T is — Signal<Option<T>> is already Copy (the signal registry hands out cheap usize addresses), so this blanket impl is sound.

Source§

impl<T: Debug + Clone + PartialEq + 'static> Debug for Previous<T>

Source§

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

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

impl<T: Clone + PartialEq + 'static> Default for Previous<T>

Default-construction for Previous.

Source§

fn default() -> Self

Constructs a default Previous value.

Source§

impl<T: Clone + PartialEq + Debug + 'static> Display for Previous<T>

Debug formatting for Previous.

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult

Formats the Previous via the supplied formatter.

§Arguments
  • &mut Formatter<'_> - The formatter receiving the formatted output.
§Returns
  • FmtResult - Result of the formatting operation.

Auto Trait Implementations§

§

impl<T> Freeze for Previous<T>
where Signal<Option<T>>: Freeze,

§

impl<T> RefUnwindSafe for Previous<T>

§

impl<T> Send for Previous<T>
where Signal<Option<T>>: Send,

§

impl<T> Sync for Previous<T>
where Signal<Option<T>>: Sync,

§

impl<T> Unpin for Previous<T>
where Signal<Option<T>>: Unpin,

§

impl<T> UnsafeUnpin for Previous<T>

§

impl<T> UnwindSafe for Previous<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, 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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, <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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more