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§

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");
});

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");
});

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");
});

Sets the stored value.


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");
});

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
🔬This is a nightly-only experimental API. (fn_traits)
Performs the call operation.
🔬This is a nightly-only experimental API. (fn_traits)
Performs the call operation.
The returned type after the call operator is used.
🔬This is a nightly-only experimental API. (fn_traits)
Performs the call operation.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the object into an [Attribute].
Converts the object into a [Class].
Converts the object into a [Property].
Converts the value into View.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more