pub struct ArcResource<T, Ser = JsonSerdeCodec> { /* private fields */ }Expand description
A reference-counted asynchronous resource.
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> ArcResource<T, Ser>where
Ser: Encoder<T> + Decoder<T>,
<Ser as Encoder<T>>::Error: Debug,
<Ser as Decoder<T>>::Error: Debug,
<<Ser as Decoder<T>>::Encoded as FromEncodedStr>::DecodingError: Debug,
<Ser as Encoder<T>>::Encoded: IntoEncodedString,
<Ser as Decoder<T>>::Encoded: FromEncodedStr,
impl<T, Ser> ArcResource<T, Ser>where
Ser: Encoder<T> + Decoder<T>,
<Ser as Encoder<T>>::Error: Debug,
<Ser as Decoder<T>>::Error: Debug,
<<Ser as Decoder<T>>::Encoded as FromEncodedStr>::DecodingError: Debug,
<Ser as Encoder<T>>::Encoded: IntoEncodedString,
<Ser as Decoder<T>>::Encoded: FromEncodedStr,
Sourcepub fn new_with_options<S, Fut>(
source: impl Fn() -> S + Send + Sync + 'static,
fetcher: impl Fn(S) -> Fut + Send + Sync + 'static,
blocking: bool,
) -> ArcResource<T, Ser>
pub fn new_with_options<S, Fut>( source: impl Fn() -> S + Send + Sync + 'static, fetcher: impl Fn(S) -> Fut + Send + Sync + 'static, blocking: bool, ) -> ArcResource<T, Ser>
Creates a new resource with the encoding Ser.
This takes a source function and a fetcher. The resource memoizes and reactively tracks
the value returned by source. Whenever that value changes, it will run the fetcher to
generate a new Future to load data.
On creation, if you are on the server, this will run the fetcher once to generate
a Future whose value will be serialized from the server to the client. If you are on
the client, the initial value will be deserialized without re-running that async task.
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> ArcResource<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> ArcResource<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> ArcResource<T, JsonSerdeCodec>where
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> ArcResource<T, JsonSerdeCodec>where
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<S, Fut>(
source: impl Fn() -> S + Send + Sync + 'static,
fetcher: impl Fn(S) -> Fut + Send + Sync + 'static,
) -> Self
pub fn new<S, Fut>( source: impl Fn() -> S + Send + Sync + 'static, fetcher: impl Fn(S) -> Fut + Send + Sync + 'static, ) -> Self
Creates a new resource with the encoding JsonSerdeCodec.
This takes a source function and a fetcher. The resource memoizes and reactively tracks
the value returned by source. Whenever that value changes, it will run the fetcher to
generate a new Future to load data.
On creation, if you are on the server, this will run the fetcher once to generate
a Future whose value will be serialized from the server to the client. If you are on
the client, the initial value will be deserialized without re-running that async task.
Sourcepub fn new_blocking<S, Fut>(
source: impl Fn() -> S + Send + Sync + 'static,
fetcher: impl Fn(S) -> Fut + Send + Sync + 'static,
) -> Self
pub fn new_blocking<S, Fut>( source: impl Fn() -> S + Send + Sync + 'static, fetcher: impl Fn(S) -> Fut + Send + Sync + 'static, ) -> Self
Creates a new blocking resource with the encoding JsonSerdeCodec.
This takes a source function and a fetcher. The resource memoizes and reactively tracks
the value returned by source. Whenever that value changes, it will run the fetcher to
generate a new Future to load data.
On creation, if you are on the server, this will run the fetcher once to generate
a Future whose value will be serialized from the server to the client. If you are on
the client, the initial value will be deserialized without re-running that async task.
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> ArcResource<T, FromToStringCodec>where
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> ArcResource<T, FromToStringCodec>where
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<S, Fut>(
source: impl Fn() -> S + Send + Sync + 'static,
fetcher: impl Fn(S) -> Fut + Send + Sync + 'static,
) -> Self
pub fn new_str<S, Fut>( source: impl Fn() -> S + Send + Sync + 'static, fetcher: impl Fn(S) -> Fut + Send + Sync + 'static, ) -> Self
Creates a new resource with the encoding FromToStringCodec.
This takes a source function and a fetcher. The resource memoizes and reactively tracks
the value returned by source. Whenever that value changes, it will run the fetcher to
generate a new Future to load data.
On creation, if you are on the server, this will run the fetcher once to generate
a Future whose value will be serialized from the server to the client. If you are on
the client, the initial value will be deserialized without re-running that async task.
Sourcepub fn new_str_blocking<S, Fut>(
source: impl Fn() -> S + Send + Sync + 'static,
fetcher: impl Fn(S) -> Fut + Send + Sync + 'static,
) -> Self
pub fn new_str_blocking<S, Fut>( source: impl Fn() -> S + Send + Sync + 'static, fetcher: impl Fn(S) -> Fut + Send + Sync + 'static, ) -> Self
Creates a new blocking resource with the encoding FromToStringCodec.
This takes a source function and a fetcher. The resource memoizes and reactively tracks
the value returned by source. Whenever that value changes, it will run the fetcher to
generate a new Future to load data.
On creation, if you are on the server, this will run the fetcher once to generate
a Future whose value will be serialized from the server to the client. If you are on
the client, the initial value will be deserialized without re-running that async task.
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, Ser> ArcResource<T, Ser>where
T: 'static,
impl<T, Ser> ArcResource<T, Ser>where
T: 'static,
Sourcepub fn by_ref(&self) -> AsyncDerivedRefFuture<T>
pub fn by_ref(&self) -> AsyncDerivedRefFuture<T>
Returns a new Future that is ready when the resource has loaded, and accesses its inner
value by reference.
Methods from Deref<Target = ArcAsyncDerived<T>>§
Sourcepub fn ready(&self) -> AsyncDerivedReadyFuture
pub fn ready(&self) -> AsyncDerivedReadyFuture
Returns a Future that is ready when this resource has next finished loading.
Sourcepub fn by_ref(&self) -> AsyncDerivedRefFuture<T>
pub fn by_ref(&self) -> AsyncDerivedRefFuture<T>
Returns a Future that resolves when the computation is finished, and accesses the inner
value by reference rather than by cloning it.
Trait Implementations§
Source§impl<T, Ser> Clone for ArcResource<T, Ser>
impl<T, Ser> Clone for ArcResource<T, Ser>
Source§impl<T, Ser> Debug for ArcResource<T, Ser>
impl<T, Ser> Debug for ArcResource<T, Ser>
Source§impl<T, Ser> DefinedAt for ArcResource<T, Ser>
impl<T, Ser> DefinedAt for ArcResource<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> Deref for ArcResource<T, Ser>
impl<T, Ser> Deref for ArcResource<T, Ser>
Source§impl<T, Ser> From<ArcResource<T, Ser>> for Resource<T, Ser>
impl<T, Ser> From<ArcResource<T, Ser>> for Resource<T, Ser>
Source§fn from(arc_resource: ArcResource<T, Ser>) -> Self
fn from(arc_resource: ArcResource<T, Ser>) -> Self
Source§impl<T, Ser> From<Resource<T, Ser>> for ArcResource<T, Ser>
impl<T, Ser> From<Resource<T, Ser>> for ArcResource<T, Ser>
Source§impl<T, Ser> IntoFuture for ArcResource<T, Ser>where
T: Clone + 'static,
impl<T, Ser> IntoFuture for ArcResource<T, Ser>where
T: Clone + 'static,
Source§type IntoFuture = AsyncDerivedFuture<T>
type IntoFuture = AsyncDerivedFuture<T>
Source§fn into_future(self) -> Self::IntoFuture
fn into_future(self) -> Self::IntoFuture
Source§impl<T, Ser> Notify for ArcResource<T, Ser>where
T: 'static,
impl<T, Ser> Notify for ArcResource<T, Ser>where
T: 'static,
Source§impl<T, Ser> ReadUntracked for ArcResource<T, Ser>where
T: 'static,
impl<T, Ser> ReadUntracked for ArcResource<T, Ser>where
T: 'static,
Source§type Value = <ArcAsyncDerived<T> as ReadUntracked>::Value
type Value = <ArcAsyncDerived<T> as ReadUntracked>::Value
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> Track for ArcResource<T, Ser>where
T: 'static,
impl<T, Ser> Track for ArcResource<T, Ser>where
T: 'static,
Source§impl<T, Ser> Write for ArcResource<T, Ser>where
T: 'static,
impl<T, Ser> Write for ArcResource<T, Ser>where
T: 'static,
Source§fn try_write(&self) -> Option<impl UntrackableGuard<Target = Self::Value>>
fn try_write(&self) -> Option<impl UntrackableGuard<Target = Self::Value>>
None if the signal has already been disposed.Source§fn try_write_untracked(&self) -> Option<impl DerefMut<Target = Self::Value>>
fn try_write_untracked(&self) -> Option<impl DerefMut<Target = Self::Value>>
None if the signal has already been disposed.Source§fn write(&self) -> impl UntrackableGuard
fn write(&self) -> impl UntrackableGuard
Source§fn write_untracked(&self) -> impl DerefMut
fn write_untracked(&self) -> impl DerefMut
Auto Trait Implementations§
impl<T, Ser> Freeze for ArcResource<T, Ser>
impl<T, Ser = JsonSerdeCodec> !RefUnwindSafe for ArcResource<T, Ser>
impl<T, Ser> Send for ArcResource<T, Ser>where
Ser: Send,
impl<T, Ser> Sync for ArcResource<T, Ser>where
Ser: Sync,
impl<T, Ser> Unpin for ArcResource<T, Ser>where
Ser: Unpin,
impl<T, Ser = JsonSerdeCodec> !UnwindSafe for ArcResource<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> Update for Twhere
T: Write,
impl<T> Update for Twhere
T: Write,
Source§fn try_maybe_update<U>(
&self,
fun: impl FnOnce(&mut <T as Update>::Value) -> (bool, U),
) -> Option<U>
fn try_maybe_update<U>( &self, fun: impl FnOnce(&mut <T as Update>::Value) -> (bool, U), ) -> Option<U>
(true, _), and returns the value returned by the update function,
or None if the signal has already been disposed.Source§fn update(&self, fun: impl FnOnce(&mut Self::Value))
fn update(&self, fun: impl FnOnce(&mut Self::Value))
Source§impl<T> UpdateUntracked for Twhere
T: Write,
impl<T> UpdateUntracked for Twhere
T: Write,
Source§fn try_update_untracked<U>(
&self,
fun: impl FnOnce(&mut <T as UpdateUntracked>::Value) -> U,
) -> Option<U>
fn try_update_untracked<U>( &self, fun: impl FnOnce(&mut <T as UpdateUntracked>::Value) -> U, ) -> Option<U>
None if the signal has already been disposed.
Does not notify subscribers that the signal has changed.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.