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_task<F, R>(&mut self, ui: &mut Ui, f: F) -> CanMakeProgress
pub fn egui_start_task<F, R>(&mut self, ui: &mut Ui, f: F) -> CanMakeProgress
Calls Self::start_task and adds a spinner if progress can be made.
if state may not be Self::None you can chain after
Self::set_none to ensure self is Self::None before calling as
self should be Self::None before calling
Sourcepub fn start_task<F, R>(&mut self, f: F) -> CanMakeProgress
pub fn start_task<F, R>(&mut self, f: F) -> CanMakeProgress
Starts a new task. Only intended to be on Self::None and if state
is any other value it returns CanMakeProgress::UnableToMakeProgress
if state may not be Self::None you can chain after
Self::set_none to ensure self is Self::None before calling
Sourcepub fn set_none(&mut self) -> &mut Self
pub fn set_none(&mut self) -> &mut Self
Resets self to Self::None and returns &mut self for chaining
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 poll_take(&mut self) -> Option<T>
pub fn poll_take(&mut self) -> Option<T>
Will poll and if in Self::Present takes the value out and returns
the owned value, leaving self reset to Self::None.
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 egui_poll_take(
&mut self,
ui: &mut Ui,
error_btn_text: Option<&str>,
) -> Option<T>
pub fn egui_poll_take( &mut self, ui: &mut Ui, error_btn_text: Option<&str>, ) -> Option<T>
Wraps Self::egui_poll_mut for the UI but instead returns the output
from Self::poll_take which will reset self to Self::None and
return the owned value if present
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.
Sourcepub fn is_awaiting_response(&self) -> bool
pub fn is_awaiting_response(&self) -> bool
Returns true if the data state is AwaitingResponse.