pub struct StoredValue<T>where
    T: 'static,{ /* private fields */ }
Expand description

A non-reactive wrapper for any value, which can be created with store_value.

If you want a reactive wrapper, use create_signal.

This allows you to create a stable reference for any value by storing it within the reactive system. Like the signal types (e.g., ReadSignal and RwSignal), it is Copy and 'static. Unlike the signal types, it is not reactive; accessing it does not cause effects to subscribe, and updating it does not notify anything else.

Implementations§

source§

impl<T> StoredValue<T>

source

pub fn get(&self) -> Twhere T: Clone,

👎Deprecated: Please use get_value instead, as this method does not track the stored value. This method will also be removed in a future version of leptos

Returns a clone of the signals current value, subscribing the effect to this signal.

Panics

Panics if you try to access a value stored in a Scope that has been disposed.

Examples

#[derive(Clone)]
pub struct MyCloneableData {
    pub value: String,
}
let data = store_value(cx, MyCloneableData { value: "a".into() });

// calling .get() clones and returns the value
assert_eq!(data.get().value, "a");
// there's a short-hand getter form
assert_eq!(data().value, "a");
source

pub fn get_value(&self) -> Twhere T: Clone,

Returns a clone of the signals current value, subscribing the effect to this signal.

Panics

Panics if you try to access a value stored in a Scope that has been disposed.

Examples

#[derive(Clone)]
pub struct MyCloneableData {
    pub value: String,
}
let data = store_value(cx, MyCloneableData { value: "a".into() });

// calling .get() clones and returns the value
assert_eq!(data.get().value, "a");
// there's a short-hand getter form
assert_eq!(data().value, "a");
source

pub fn try_get(&self) -> Option<T>where T: Clone,

👎Deprecated: Please use try_get_value instead, as this method does not track the stored value. This method will also be removed in a future version of leptos

Same as StoredValue::get but will not panic by default.

source

pub fn try_get_value(&self) -> Option<T>where T: Clone,

Same as StoredValue::get but will not panic by default.

source

pub fn with<U>(&self, f: impl FnOnce(&T) -> U) -> U

👎Deprecated: Please use with_value instead, as this method does not track the stored value. This method will also be removed in a future version of leptos

Applies a function to the current stored value.

Panics

Panics if you try to access a value stored in a Scope that has been disposed.

Examples

pub struct MyUncloneableData {
  pub value: String
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });

// calling .with() to extract the value
assert_eq!(data.with(|data| data.value.clone()), "a");
});
source

pub fn with_value<U>(&self, f: impl FnOnce(&T) -> U) -> U

Applies a function to the current stored value.

Panics

Panics if you try to access a value stored in a Scope that has been disposed.

Examples

pub struct MyUncloneableData {
    pub value: String,
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });

// calling .with() to extract the value
assert_eq!(data.with(|data| data.value.clone()), "a");
source

pub fn try_with<O>(&self, f: impl FnOnce(&T) -> O) -> Option<O>

👎Deprecated: Please use try_with_value instead, as this method does not track the stored value. This method will also be removed in a future version of leptos

Same as StoredValue::with but returns [Some(O)] only if the signal is still valid. None otherwise.

source

pub fn try_with_value<O>(&self, f: impl FnOnce(&T) -> O) -> Option<O>

Same as StoredValue::with but returns [Some(O)] only if the signal is still valid. None otherwise.

source

pub fn update(&self, f: impl FnOnce(&mut T))

👎Deprecated: Please use update_value instead, as this method does not track the stored value. This method will also be removed in a future version of leptos

Updates the stored value.

Examples

pub struct MyUncloneableData {
  pub value: String
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });
data.update(|data| data.value = "b".into());
assert_eq!(data.with(|data| data.value.clone()), "b");
});
use leptos_reactive::*;

pub struct MyUncloneableData {
    pub value: String,
}

let data = store_value(cx, MyUncloneableData { value: "a".into() });
let updated = data.update_returning(|data| {
    data.value = "b".into();
    data.value.clone()
});

assert_eq!(data.with(|data| data.value.clone()), "b");
assert_eq!(updated, Some(String::from("b")));
source

pub fn update_value(&self, f: impl FnOnce(&mut T))

Updates the stored value.

Examples

pub struct MyUncloneableData {
  pub value: String
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });
data.update(|data| data.value = "b".into());
assert_eq!(data.with(|data| data.value.clone()), "b");
});
use leptos_reactive::*;

pub struct MyUncloneableData {
    pub value: String,
}

let data = store_value(cx, MyUncloneableData { value: "a".into() });
let updated = data.update_returning(|data| {
    data.value = "b".into();
    data.value.clone()
});

assert_eq!(data.with(|data| data.value.clone()), "b");
assert_eq!(updated, Some(String::from("b")));
source

pub fn update_returning<U>(&self, f: impl FnOnce(&mut T) -> U) -> Option<U>

👎Deprecated: Please use try_update_value instead, as this method does not track the stored value. This method will also be removed in a future version of leptos

Updates the stored value.

source

pub fn try_update_value<O>(self, f: impl FnOnce(&mut T) -> O) -> Option<O>

Same as Self::update, but returns [Some(O)] if the signal is still valid, None otherwise.

source

pub fn set(&self, value: T)

👎Deprecated: Please use set_value instead, as this method does not track the stored value. This method will also be removed in a future version of leptos

Sets the stored value.

Examples

pub struct MyUncloneableData {
  pub value: String
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });
data.set(MyUncloneableData { value: "b".into() });
assert_eq!(data.with(|data| data.value.clone()), "b");
});
source

pub fn set_value(&self, value: T)

Sets the stored value.

Examples

pub struct MyUncloneableData {
    pub value: String,
}
let data = store_value(cx, MyUncloneableData { value: "a".into() });
data.set(MyUncloneableData { value: "b".into() });
assert_eq!(data.with(|data| data.value.clone()), "b");
source

pub fn try_set_value(&self, value: T) -> Option<T>

Same as Self::set, but returns None if the signal is still valid, [Some(T)] otherwise.

Trait Implementations§

source§

impl<T> Clone for StoredValue<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<T> Debug for StoredValue<T>where T: 'static + Debug,

source§

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

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

impl<T> Hash for StoredValue<T>where T: 'static + Hash,

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T> PartialEq<StoredValue<T>> for StoredValue<T>where T: 'static + PartialEq,

source§

fn eq(&self, other: &StoredValue<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Copy for StoredValue<T>

source§

impl<T> Eq for StoredValue<T>where T: 'static + Eq,

source§

impl<T> StructuralEq for StoredValue<T>where T: 'static,

source§

impl<T> StructuralPartialEq for StoredValue<T>where T: 'static,

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for StoredValue<T>where T: RefUnwindSafe,

§

impl<T> Send for StoredValue<T>where T: Send,

§

impl<T> Sync for StoredValue<T>where T: Sync,

§

impl<T> Unpin for StoredValue<T>where T: Unpin,

§

impl<T> UnwindSafe for StoredValue<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CallHasher for Twhere T: Hash + ?Sized,

source§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64where H: Hash + ?Sized, B: BuildHasher,

source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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