pub struct OnceResource<T, Ser = JsonSerdeCodec> { /* private fields */ }Expand description
A resource that only loads once.
Resources allow asynchronously loading data and serializing it from the server to the client, so that it loads on the server, and is then deserialized on the client. This improves performance by beginning data loading on the server when the request is made, rather than beginning it on the client after WASM has been loaded.
You can access the value of the resource either synchronously using .get() or asynchronously
using .await.
Implementations§
Source§impl<T, Ser> OnceResource<T, Ser>
impl<T, Ser> OnceResource<T, Ser>
Sourcepub fn new_with_options(
fut: impl Future<Output = T> + Send + 'static,
blocking: bool,
) -> OnceResource<T, Ser>
pub fn new_with_options( fut: impl Future<Output = T> + Send + 'static, blocking: bool, ) -> OnceResource<T, Ser>
Creates a new resource with the encoding Ser. If blocking is true, this is a blocking
resource.
Blocking resources prevent any of the HTTP response from being sent until they have loaded. This is useful if you need their data to set HTML document metadata or information that needs to appear in HTTP headers.
Source§impl<T, E, Ser> OnceResource<Result<T, E>, Ser>where
Ser: Encoder<Result<T, E>> + Decoder<Result<T, E>>,
<Ser as Encoder<Result<T, E>>>::Error: Debug,
<Ser as Decoder<Result<T, E>>>::Error: Debug,
<<Ser as Decoder<Result<T, E>>>::Encoded as FromEncodedStr>::DecodingError: Debug,
<Ser as Encoder<Result<T, E>>>::Encoded: IntoEncodedString,
<Ser as Decoder<Result<T, E>>>::Encoded: FromEncodedStr,
T: Send + Sync + 'static,
E: Send + Sync + Clone + 'static,
impl<T, E, Ser> OnceResource<Result<T, E>, Ser>where
Ser: Encoder<Result<T, E>> + Decoder<Result<T, E>>,
<Ser as Encoder<Result<T, E>>>::Error: Debug,
<Ser as Decoder<Result<T, E>>>::Error: Debug,
<<Ser as Decoder<Result<T, E>>>::Encoded as FromEncodedStr>::DecodingError: Debug,
<Ser as Encoder<Result<T, E>>>::Encoded: IntoEncodedString,
<Ser as Decoder<Result<T, E>>>::Encoded: FromEncodedStr,
T: Send + Sync + 'static,
E: Send + Sync + Clone + 'static,
Sourcepub fn and_then<U>(&self, f: impl FnOnce(&T) -> U) -> Option<Result<U, E>>
pub fn and_then<U>(&self, f: impl FnOnce(&T) -> U) -> Option<Result<U, E>>
Applies the given function when a resource that returns Result<T, E>
has resolved and loaded an Ok(_), rather than requiring nested .map()
calls over the Option<Result<_, _>> returned by the resource.
This is useful when used with features like server functions, in conjunction
with <ErrorBoundary/> and <Suspense/>, when these other components are
left to handle the None and Err(_) states.
Source§impl<T, Ser> OnceResource<T, Ser>
impl<T, Ser> OnceResource<T, Ser>
Sourcepub fn ready(&self) -> AsyncDerivedReadyFuture ⓘ
pub fn ready(&self) -> AsyncDerivedReadyFuture ⓘ
Returns a Future that is ready when this resource has next finished loading.
Source§impl<T> OnceResource<T>where
T: Send + Sync + 'static,
JsonSerdeCodec: Encoder<T> + Decoder<T>,
<JsonSerdeCodec as Encoder<T>>::Error: Debug,
<JsonSerdeCodec as Decoder<T>>::Error: Debug,
<<JsonSerdeCodec as Decoder<T>>::Encoded as FromEncodedStr>::DecodingError: Debug,
<JsonSerdeCodec as Encoder<T>>::Encoded: IntoEncodedString,
<JsonSerdeCodec as Decoder<T>>::Encoded: FromEncodedStr,
impl<T> OnceResource<T>where
T: Send + Sync + 'static,
JsonSerdeCodec: Encoder<T> + Decoder<T>,
<JsonSerdeCodec as Encoder<T>>::Error: Debug,
<JsonSerdeCodec as Decoder<T>>::Error: Debug,
<<JsonSerdeCodec as Decoder<T>>::Encoded as FromEncodedStr>::DecodingError: Debug,
<JsonSerdeCodec as Encoder<T>>::Encoded: IntoEncodedString,
<JsonSerdeCodec as Decoder<T>>::Encoded: FromEncodedStr,
Sourcepub fn new(fut: impl Future<Output = T> + Send + 'static) -> OnceResource<T>
pub fn new(fut: impl Future<Output = T> + Send + 'static) -> OnceResource<T>
Creates a resource using JsonSerdeCodec for encoding/decoding the value.
Sourcepub fn new_blocking(
fut: impl Future<Output = T> + Send + 'static,
) -> OnceResource<T>
pub fn new_blocking( fut: impl Future<Output = T> + Send + 'static, ) -> OnceResource<T>
Creates a blocking resource using JsonSerdeCodec for encoding/decoding the value.
Blocking resources prevent any of the HTTP response from being sent until they have loaded. This is useful if you need their data to set HTML document metadata or information that needs to appear in HTTP headers.
Source§impl<T> OnceResource<T, FromToStringCodec>where
T: Send + Sync + 'static,
FromToStringCodec: Encoder<T> + Decoder<T>,
<FromToStringCodec as Encoder<T>>::Error: Debug,
<FromToStringCodec as Decoder<T>>::Error: Debug,
<<FromToStringCodec as Decoder<T>>::Encoded as FromEncodedStr>::DecodingError: Debug,
<FromToStringCodec as Encoder<T>>::Encoded: IntoEncodedString,
<FromToStringCodec as Decoder<T>>::Encoded: FromEncodedStr,
impl<T> OnceResource<T, FromToStringCodec>where
T: Send + Sync + 'static,
FromToStringCodec: Encoder<T> + Decoder<T>,
<FromToStringCodec as Encoder<T>>::Error: Debug,
<FromToStringCodec as Decoder<T>>::Error: Debug,
<<FromToStringCodec as Decoder<T>>::Encoded as FromEncodedStr>::DecodingError: Debug,
<FromToStringCodec as Encoder<T>>::Encoded: IntoEncodedString,
<FromToStringCodec as Decoder<T>>::Encoded: FromEncodedStr,
Sourcepub fn new_str(
fut: impl Future<Output = T> + Send + 'static,
) -> OnceResource<T, FromToStringCodec>
pub fn new_str( fut: impl Future<Output = T> + Send + 'static, ) -> OnceResource<T, FromToStringCodec>
Creates a resource using FromToStringCodec for encoding/decoding the value.
Sourcepub fn new_str_blocking(
fut: impl Future<Output = T> + Send + 'static,
) -> OnceResource<T, FromToStringCodec>
pub fn new_str_blocking( fut: impl Future<Output = T> + Send + 'static, ) -> OnceResource<T, FromToStringCodec>
Creates a blocking resource using FromToStringCodec for encoding/decoding the value.
Blocking resources prevent any of the HTTP response from being sent until they have loaded. This is useful if you need their data to set HTML document metadata or information that needs to appear in HTTP headers.
Trait Implementations§
Source§impl<T, Ser> Clone for OnceResource<T, Ser>
impl<T, Ser> Clone for OnceResource<T, Ser>
Source§fn clone(&self) -> OnceResource<T, Ser>
fn clone(&self) -> OnceResource<T, Ser>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<T, Ser> Copy for OnceResource<T, Ser>
Source§impl<T, Ser> Debug for OnceResource<T, Ser>
impl<T, Ser> Debug for OnceResource<T, Ser>
Source§impl<T, Ser> DefinedAt for OnceResource<T, Ser>
impl<T, Ser> DefinedAt for OnceResource<T, Ser>
Source§fn defined_at(&self) -> Option<&'static Location<'static>>
fn defined_at(&self) -> Option<&'static Location<'static>>
None in
release mode.Source§impl<T, Ser> IntoFuture for OnceResource<T, Ser>
impl<T, Ser> IntoFuture for OnceResource<T, Ser>
Source§type IntoFuture = OnceResourceFuture<T>
type IntoFuture = OnceResourceFuture<T>
Source§fn into_future(self) -> <OnceResource<T, Ser> as IntoFuture>::IntoFuture
fn into_future(self) -> <OnceResource<T, Ser> as IntoFuture>::IntoFuture
Source§impl<T, Ser> IsDisposed for OnceResource<T, Ser>
impl<T, Ser> IsDisposed for OnceResource<T, Ser>
Source§fn is_disposed(&self) -> bool
fn is_disposed(&self) -> bool
true, the signal cannot be accessed without a panic.Source§impl<T, Ser> ReadUntracked for OnceResource<T, Ser>
impl<T, Ser> ReadUntracked for OnceResource<T, Ser>
Source§type Value = ReadGuard<Option<T>, Plain<Option<T>>>
type Value = ReadGuard<Option<T>, Plain<Option<T>>>
Source§fn try_read_untracked(
&self,
) -> Option<<OnceResource<T, Ser> as ReadUntracked>::Value>
fn try_read_untracked( &self, ) -> Option<<OnceResource<T, Ser> as ReadUntracked>::Value>
None if the signal has already been disposed.Source§fn read_untracked(&self) -> Self::Value
fn read_untracked(&self) -> Self::Value
Source§fn custom_try_read(&self) -> Option<Option<Self::Value>>
fn custom_try_read(&self) -> Option<Option<Self::Value>>
Read::try_read implementation despite it being auto implemented. Read moreSource§impl<T, Ser> ToAnySource for OnceResource<T, Ser>
impl<T, Ser> ToAnySource for OnceResource<T, Ser>
Source§fn to_any_source(&self) -> AnySource
fn to_any_source(&self) -> AnySource
Auto Trait Implementations§
impl<T, Ser> Freeze for OnceResource<T, Ser>
impl<T, Ser> RefUnwindSafe for OnceResource<T, Ser>
impl<T, Ser> Send for OnceResource<T, Ser>
impl<T, Ser> Sync for OnceResource<T, Ser>
impl<T, Ser> Unpin for OnceResource<T, Ser>
impl<T, Ser> UnsafeUnpin for OnceResource<T, Ser>
impl<T, Ser> UnwindSafe for OnceResource<T, Ser>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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> 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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Read for Twhere
T: Track + ReadUntracked,
impl<T> Read for Twhere
T: Track + ReadUntracked,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> SerializableAny for T
Source§impl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
Source§fn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
Source§fn into_taken(self) -> T
fn into_taken(self) -> T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
fn to_sample_(self) -> U
Source§impl<S, T> Upcast<T> for S
impl<S, T> Upcast<T> for S
impl<T> WasmNotSend for Twhere
T: Send,
impl<T> WasmNotSendSync for Twhere
T: WasmNotSend + WasmNotSync,
impl<T> WasmNotSync for Twhere
T: Sync,
Source§impl<T> With for Twhere
T: Read,
impl<T> With for Twhere
T: Read,
Source§type Value = <<T as Read>::Value as Deref>::Target
type Value = <<T as Read>::Value as Deref>::Target
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Source§impl<T> WithUntracked for Twhere
T: DefinedAt + ReadUntracked,
impl<T> WithUntracked for Twhere
T: DefinedAt + ReadUntracked,
Source§type Value = <<T as ReadUntracked>::Value as Deref>::Target
type Value = <<T as ReadUntracked>::Value as Deref>::Target
Source§fn try_with_untracked<U>(
&self,
fun: impl FnOnce(&<T as WithUntracked>::Value) -> U,
) -> Option<U>
fn try_with_untracked<U>( &self, fun: impl FnOnce(&<T as WithUntracked>::Value) -> U, ) -> Option<U>
None if the signal has already been disposed.