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
.