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) -> SharedValue<T>
pub fn new(initial: impl FnOnce() -> T) -> SharedValue<T>
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) -> SharedValue<T, FromToStringCodec>
pub fn new_str(initial: impl FnOnce() -> T) -> SharedValue<T, FromToStringCodec>
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) -> SharedValue<T, Ser>
pub fn new_with_encoding(initial: impl FnOnce() -> T) -> SharedValue<T, Ser>
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.
Trait Implementations§
Source§fn cmp(&self, other: &SharedValue<T, Ser>) -> Ordering
fn cmp(&self, other: &SharedValue<T, Ser>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more