pub enum DataState<T, E: ErrorBounds = Error> {
None,
AwaitingResponse(Awaiting<T, E>),
Present(T),
Failed(DataStateError<E>),
}Expand description
Used to store a type that is not always available and we need to keep polling it to get it ready
Variants§
None
Represent no data present and not pending
AwaitingResponse(Awaiting<T, E>)
Represents data has been requested and awaiting it being available
Present(T)
Represents data that is available for use
Failed(DataStateError<E>)
Represents an error that Occurred
Implementations§
Source§impl<T, E: ErrorBounds> DataState<T, E>
impl<T, E: ErrorBounds> DataState<T, E>
Sourcepub fn egui_get<F>(
&mut self,
ui: &mut Ui,
retry_msg: Option<&str>,
fetch_fn: F,
) -> CanMakeProgress
pub fn egui_get<F>( &mut self, ui: &mut Ui, retry_msg: Option<&str>, fetch_fn: F, ) -> CanMakeProgress
Attempts to load the data and displays appropriate UI if applicable. Some branches lead to no UI being displayed, in particular when the data or an error is received (On the expectation it will show next frame). When in an error state the error messages will show as applicable. If called an already has data present this function does nothing and returns [CanMakeProgress::UnableToMakeProgress]
If a retry_msg is provided then it overrides the default
Note see Self::get for more info.
Sourcepub fn get<F>(&mut self, fetch_fn: F) -> CanMakeProgress
pub fn get<F>(&mut self, fetch_fn: F) -> CanMakeProgress
Attempts to load the data and returns if it is able to make progress.
Note: F needs to return AwaitingType<T> and not T because it needs to
be able to be pending if T is not ready.
Sourcepub fn await_data(rx: &mut Awaiting<T, E>) -> Option<Self>
pub fn await_data(rx: &mut Awaiting<T, E>) -> Option<Self>
Checks to see if the data is ready and if it is returns a new Self
otherwise None
Sourcepub fn is_present(&self) -> bool
pub fn is_present(&self) -> bool
Returns true if the data state is Present.
Trait Implementations§
Auto Trait Implementations§
impl<T, E> Freeze for DataState<T, E>
impl<T, E = Error> !RefUnwindSafe for DataState<T, E>
impl<T, E> Send for DataState<T, E>where
T: Send,
impl<T, E> Sync for DataState<T, E>
impl<T, E> Unpin for DataState<T, E>
impl<T, E = Error> !UnwindSafe for DataState<T, E>
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> 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 more