pub struct SharedValue<T, Ser = JsonSerdeCodec> { /* private fields */ }Expand description
A smart pointer that allows you to share identical, synchronously-loaded data between the server and the client.
If this constructed on the server, it serializes its value into the shared context. If it is constructed on the client during hydration, it reads its value from the shared context. If it it constructed on the client at any other time, it simply runs on the client.
Implementations§
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Returns the inner value.
Sourcepub fn new(initial: impl FnOnce() -> T) -> Self
pub fn new(initial: impl FnOnce() -> T) -> Self
Wraps the initial value.
If this is on the server, the function will be invoked and the value serialized. When it runs on the client, it will be deserialized without running the function again.
This uses the JsonSerdeCodec encoding.
Sourcepub fn new_str(initial: impl FnOnce() -> T) -> Self
pub fn new_str(initial: impl FnOnce() -> T) -> Self
Wraps the initial value.
If this is on the server, the function will be invoked and the value serialized. When it runs on the client, it will be deserialized without running the function again.
This uses the FromToStringCodec encoding.
Sourcepub fn new_with_encoding(initial: impl FnOnce() -> T) -> Self
pub fn new_with_encoding(initial: impl FnOnce() -> T) -> Self
Wraps the initial value.
If this is on the server, the function will be invoked and the value serialized. When it runs on the client, it will be deserialized without running the function again.
This uses Ser as an encoding.