Struct leptos::StoredValue
source · pub struct StoredValue<T>(_)
where
T: 'static;
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>where
T: 'static,
impl<T> StoredValue<T>where
T: 'static,
sourcepub fn get(&self) -> Twhere
T: Clone,
pub fn get(&self) -> Twhere
T: Clone,
Clones and returns the current stored value.
If you want to get the value without cloning it, use StoredValue::with.
(value.get()
is equivalent to value.with(T::clone)
.)
#[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");
});
sourcepub fn with<U>(&self, f: impl FnOnce(&T) -> U) -> U
pub fn with<U>(&self, f: impl FnOnce(&T) -> U) -> U
Applies a function to the current stored value.
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");
});
sourcepub fn update(&self, f: impl FnOnce(&mut T))
pub fn update(&self, f: impl FnOnce(&mut T))
Applies a function to the current value to mutate it in place.
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");
});
Trait Implementations§
source§impl<T> Clone for StoredValue<T>
impl<T> Clone for StoredValue<T>
source§fn clone(&self) -> StoredValue<T>
fn clone(&self) -> StoredValue<T>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<T> Debug for StoredValue<T>where
T: Debug + 'static,
impl<T> Debug for StoredValue<T>where
T: Debug + 'static,
source§impl<T> Fn() for StoredValue<T>where
T: Clone,
impl<T> Fn() for StoredValue<T>where
T: Clone,
source§impl<T> FnMut() for StoredValue<T>where
T: Clone,
impl<T> FnMut() for StoredValue<T>where
T: Clone,
source§impl<T> FnOnce() for StoredValue<T>where
T: Clone,
impl<T> FnOnce() for StoredValue<T>where
T: Clone,
source§impl<T> Hash for StoredValue<T>where
T: Hash + 'static,
impl<T> Hash for StoredValue<T>where
T: Hash + 'static,
source§impl<T> PartialEq<StoredValue<T>> for StoredValue<T>where
T: PartialEq<T> + 'static,
impl<T> PartialEq<StoredValue<T>> for StoredValue<T>where
T: PartialEq<T> + 'static,
source§fn eq(&self, other: &StoredValue<T>) -> bool
fn eq(&self, other: &StoredValue<T>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl<T> Copy for StoredValue<T>
impl<T> Eq for StoredValue<T>where
T: Eq + 'static,
impl<T> StructuralEq for StoredValue<T>where
T: 'static,
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> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T, U> IntoAttribute for Twhere
T: 'static + Fn() -> U,
U: IntoAttribute,
impl<T, U> IntoAttribute for Twhere
T: 'static + Fn() -> U,
U: IntoAttribute,
source§fn into_attribute(self, cx: Scope) -> Attribute
fn into_attribute(self, cx: Scope) -> Attribute
Converts the object into an [Attribute].
source§impl<T> IntoClass for Twhere
T: 'static + Fn() -> bool,
impl<T> IntoClass for Twhere
T: 'static + Fn() -> bool,
source§fn into_class(self, cx: Scope) -> Class
fn into_class(self, cx: Scope) -> Class
Converts the object into a [Class].
source§impl<T, U> IntoProperty for Twhere
T: 'static + Fn() -> U,
U: Into<JsValue>,
impl<T, U> IntoProperty for Twhere
T: 'static + Fn() -> U,
U: Into<JsValue>,
source§fn into_property(self, cx: Scope) -> Property
fn into_property(self, cx: Scope) -> Property
Converts the object into a [Property].