pub enum RemoteData<T, E = String> {
NotAsked,
Loading,
Success(T),
Failure(E),
}Expand description
The four states of an asynchronously loaded value.
E, the error type, defaults to String — the common case after
FetchError::to_string().
Variants§
NotAsked
Nothing has been asked for yet; the initial state.
Loading
A request is in flight.
Success(T)
The value has arrived.
Failure(E)
The request failed.
Implementations§
Source§impl<T, E> RemoteData<T, E>
impl<T, E> RemoteData<T, E>
Sourcepub fn from_result(res: Result<T, E>) -> Self
pub fn from_result(res: Result<T, E>) -> Self
Sourcepub fn is_loading(&self) -> bool
pub fn is_loading(&self) -> bool
Is a request in flight?
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Has the value arrived?
Sourcepub fn is_failure(&self) -> bool
pub fn is_failure(&self) -> bool
Did the request fail?
Sourcepub fn as_ref(&self) -> RemoteData<&T, &E>
pub fn as_ref(&self) -> RemoteData<&T, &E>
Borrows the inside: RemoteData<T, E> → RemoteData<&T, &E>, so a view can
fold over it without consuming the state.
Sourcepub fn map<U>(self, f: impl FnOnce(T) -> U) -> RemoteData<U, E>
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> RemoteData<U, E>
Transforms the value on success, leaving the other states untouched — decoding a JSON body into a domain type, say.
Sourcepub fn map_err<F>(self, f: impl FnOnce(E) -> F) -> RemoteData<T, F>
pub fn map_err<F>(self, f: impl FnOnce(E) -> F) -> RemoteData<T, F>
Transforms the error on failure, leaving the other states untouched.
Trait Implementations§
Source§impl<T, E> Default for RemoteData<T, E>
impl<T, E> Default for RemoteData<T, E>
impl<T: Eq, E: Eq> Eq for RemoteData<T, E>
impl<T: PartialEq, E: PartialEq> StructuralPartialEq for RemoteData<T, E>
Auto Trait Implementations§
impl<T, E> Freeze for RemoteData<T, E>
impl<T, E> RefUnwindSafe for RemoteData<T, E>where
T: RefUnwindSafe,
E: RefUnwindSafe,
impl<T, E> Send for RemoteData<T, E>
impl<T, E> Sync for RemoteData<T, E>
impl<T, E> Unpin for RemoteData<T, E>
impl<T, E> UnsafeUnpin for RemoteData<T, E>where
T: UnsafeUnpin,
E: UnsafeUnpin,
impl<T, E> UnwindSafe for RemoteData<T, E>where
T: UnwindSafe,
E: UnwindSafe,
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
Mutably borrows from an owned value. Read more
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>
Convert
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>
Convert
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)
Convert
&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)
Convert
&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> DowncastSync for T
impl<T> DowncastSync for T
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
Compare self to
key and return true if they are equal.