Skip to main content

euv_ui/hook/use_async/
enum.rs

1/// Discriminant for the three states an `use_async` future can be in.
2///
3/// Re-exported as `UseAsyncState` via [`super`]. Kept as a separate
4/// enum (rather than a `Result`-shaped type) so the `match` arms
5/// produced by users can name the `Loading` case separately and
6/// reach for `LoadingHint` (the previous "in flight" payload) when
7/// available.
8///
9/// The default initial state is `Loading(LoadingHint::DEFAULT)`,
10/// because until the first `.await` resolves there is no `T` to
11/// report. Users that need a distinct pre-fetch state can supply
12/// `LoadingHint` via `UseAsyncHandle::loading_hint()`.
13#[derive(Clone, Debug, Eq, PartialEq)]
14pub enum AsyncState<T, L = ()> {
15    /// The future has not yet produced a value (initial state).
16    Loading(L),
17    /// The future completed successfully with `T`.
18    Ok(T),
19    /// The future rejected with an error of type `E`.
20    ///
21    /// We intentionally use a free-form `String` for the error
22    /// payload so the same enum works whether the future's error
23    /// type is `JsValue`, `String`, `serde_json::Value`, or a custom
24    /// domain type — `use_async` normalises everything into
25    /// `String::to_string` at the await boundary. Callers that need
26    /// typed errors should `String::parse` or use a richer future
27    /// combinator on top.
28    Err(String),
29}