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,
) -> Self
pub fn new_with_options( fut: impl Future<Output = T> + Send + 'static, blocking: bool, ) -> Self
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, JsonSerdeCodec>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, JsonSerdeCodec>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) -> Self
pub fn new(fut: impl Future<Output = T> + Send + 'static) -> Self
Creates a resource using JsonSerdeCodec for encoding/decoding the value.
Sourcepub fn new_blocking(fut: impl Future<Output = T> + Send + 'static) -> Self
pub fn new_blocking(fut: impl Future<Output = T> + Send + 'static) -> Self
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) -> Self
pub fn new_str(fut: impl Future<Output = T> + Send + 'static) -> Self
Creates a resource using FromToStringCodec for encoding/decoding the value.
Sourcepub fn new_str_blocking(fut: impl Future<Output = T> + Send + 'static) -> Self
pub fn new_str_blocking(fut: impl Future<Output = T> + Send + 'static) -> Self
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§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) -> Self::IntoFuture
fn into_future(self) -> Self::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<Self::Value>
fn try_read_untracked(&self) -> Option<Self::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
Source§impl<T, Ser> Track for OnceResource<T, Ser>
impl<T, Ser> Track for OnceResource<T, Ser>
impl<T, Ser> Copy for OnceResource<T, Ser>
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Read for Twhere
T: Track + ReadUntracked,
impl<T> Read for Twhere
T: Track + ReadUntracked,
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<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> 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.