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_start_request<F, R>(
&mut self,
ui: &mut Ui,
fetch_fn: F,
) -> CanMakeProgress
pub fn egui_start_request<F, R>( &mut self, ui: &mut Ui, fetch_fn: F, ) -> CanMakeProgress
Calls Self::start_request and adds a spinner if progress can be made
Sourcepub fn start_request<F, R>(&mut self, fetch_fn: F) -> CanMakeProgress
pub fn start_request<F, R>(&mut self, fetch_fn: F) -> CanMakeProgress
Starts a new request. Only intended to be on Self::None and if state is any other value it returns [CanMakeProgress::UnableToMakeProgress]
Sourcepub fn poll(&mut self) -> &mut Self
pub fn poll(&mut self) -> &mut Self
Convenience method that will try to make progress if in Self::AwaitingResponse and does nothing otherwise. Returns a reference to self for chaining
Sourcepub fn egui_poll_mut(
&mut self,
ui: &mut Ui,
error_btn_text: Option<&str>,
) -> Option<&mut T>
pub fn egui_poll_mut( &mut self, ui: &mut Ui, error_btn_text: Option<&str>, ) -> Option<&mut T>
Meant to be a simple method to just provide the data if it’s ready or help with UI and polling to get it ready if it’s not.
WARNING: Does nothing if self is Self::None
If a error_btn_text is provided then it overrides the default
Sourcepub fn egui_poll(
&mut self,
ui: &mut Ui,
error_btn_text: Option<&str>,
) -> Option<&T>
pub fn egui_poll( &mut self, ui: &mut Ui, error_btn_text: Option<&str>, ) -> Option<&T>
Wraps Self::egui_poll_mut and returns an immutable reference
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 present(&self) -> Option<&T>
pub fn present(&self) -> Option<&T>
Returns a reference to the inner data if available otherwise None.
NOTE: This function does not poll to get the data ready if the state is still awaiting
Sourcepub fn present_mut(&mut self) -> Option<&mut T>
pub fn present_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the inner data if available otherwise None
NOTE: This function does not poll to get the data ready if the state is still awaiting
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