pub struct Fetcher<I: Send + 'static, O> { /* private fields */ }Expand description
A value factory that uses the result of an asynchronous task to compute an output value.
The fetcher takes a task and a factory function.
It produces an output value O by taking an Option of an input value I.
If the inner Task is not ready yet, the factory will be called with None.
Once the inner Task is ready, the factory will be called with Some(I).
This is similar to the FutureBuilder from Flutter.
Implementations§
Source§impl<I: Send + 'static, O> Fetcher<I, O>
impl<I: Send + 'static, O> Fetcher<I, O>
Sourcepub const fn new(
task: Box<dyn Task<I>>,
factory: Box<dyn Fn(Option<I>) -> O + 'static>,
) -> Self
pub const fn new( task: Box<dyn Task<I>>, factory: Box<dyn Fn(Option<I>) -> O + 'static>, ) -> Self
Create a new task fetcher with the given task and factory function.
Sourcepub fn spawn(
future: impl Future<Output = I> + Send + 'static,
factory: impl Fn(Option<I>) -> O + 'static,
) -> Self
pub fn spawn( future: impl Future<Output = I> + Send + 'static, factory: impl Fn(Option<I>) -> O + 'static, ) -> Self
Spawn a future using the TaskRunner and create a new Fetcher with the resulting task and the given factory function.
If you want to spawn a blocking task, use Fetcher::spawn_blocking instead.
Sourcepub fn spawn_blocking(
func: impl Fn() -> I + Send + 'static,
factory: impl Fn(Option<I>) -> O + 'static,
) -> Self
pub fn spawn_blocking( func: impl Fn() -> I + Send + 'static, factory: impl Fn(Option<I>) -> O + 'static, ) -> Self
Spawn a blocking function using the TaskRunner and create a new Fetcher with the resulting task and the given factory function.
If your task is non-blocking (a simple future), use Fetcher::spawn instead.
Sourcepub const fn value_mut(&mut self) -> Option<&mut O>
pub const fn value_mut(&mut self) -> Option<&mut O>
Returns a mutable reference to the possible output value.
This is mostly used internally and will return the cached output value.
Sourcepub const fn value_ref(&self) -> Option<&O>
pub const fn value_ref(&self) -> Option<&O>
Returns a reference to the possible output value.
This is mostly used internally and will return the cached output value.
Sourcepub fn is_ready(&self) -> bool
pub fn is_ready(&self) -> bool
Returns whether the inner task is ready.
NOTE: This will only return true, if the inner task has finished,
but the value has not been consumed yet.
Sourcepub const fn is_fetched(&self) -> bool
pub const fn is_fetched(&self) -> bool
Returns whether the inner task has finished and the value has been computed.
Auto Trait Implementations§
impl<I, O> Freeze for Fetcher<I, O>where
O: Freeze,
impl<I, O> !RefUnwindSafe for Fetcher<I, O>
impl<I, O> !Send for Fetcher<I, O>
impl<I, O> !Sync for Fetcher<I, O>
impl<I, O> Unpin for Fetcher<I, O>where
O: Unpin,
impl<I, O> !UnwindSafe for Fetcher<I, O>
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> 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> 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<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.