Skip to main content

LoadState

Enum LoadState 

Source
pub enum LoadState<T> {
    Idle,
    Loading,
    Ready(Rc<T>),
    Refreshing(Rc<T>),
    Failed {
        message: Rc<str>,
        data: Option<Rc<T>>,
    },
}
Expand description

异步数据 + 进度。T 通常是 Vec<Row> / Rc<Vec<Item>> 这类可共享快照。

Variants§

§

Idle

尚未开始

§

Loading

首次加载中,还没有数据

§

Ready(Rc<T>)

已有数据

§

Refreshing(Rc<T>)

已有数据且正在刷新:继续画旧数据,叠加轻量指示器,避免列表闪空

§

Failed

失败;data 是上一次成功取到的数据(可能为 None)

Fields

§message: Rc<str>
§data: Option<Rc<T>>

Implementations§

Source§

impl<T> LoadState<T>

Source

pub fn ready(value: T) -> Self

Source

pub fn ready_rc(value: Rc<T>) -> Self

Source

pub fn failed(message: impl Into<Rc<str>>) -> Self

Source

pub fn status(&self) -> LoadStatus

可直接交给组件的进度值

Source

pub fn data(&self) -> Option<&Rc<T>>

当前可画的数据(含刷新中/失败时保留的旧数据)

Source

pub fn into_data(self) -> Option<Rc<T>>

Source

pub fn message(&self) -> Option<&str>

Source

pub fn is_pending(&self) -> bool

有进行中的取数(首载或刷新)

Source

pub fn is_failed(&self) -> bool

Source

pub fn begin(&self) -> Self

开始一次取数:有旧数据则进入 Refreshing(继续画旧数据),否则 Loading。

Source

pub fn finish(&self, value: T) -> Self

取数成功:数据换成新值,进度回到 Ready。

Source

pub fn fail(&self, message: impl Into<Rc<str>>) -> Self

取数失败:保留旧数据(供重试时继续显示),记录原因。

Source

pub fn map<U, F: FnOnce(&T) -> U>(&self, f: F) -> LoadState<U>

换一种数据形态(例如 LoadState<Vec<Item>> → LoadState<Vec RowView>>)。 取数中/失败没有数据时按 Idle/Failed 原样映射。

Source§

impl<T> LoadState<T>
where T: Clone + 'static,

Source

pub fn signal(self) -> Signal<LoadState<T>>

建一个承载本状态的 Signal(应用最常用的形状)。

Trait Implementations§

Source§

impl<T: Clone> Clone for LoadState<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for LoadState<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for LoadState<T>

手写而非 #[derive(Default)]:derive 会给枚举的所有变体加 T: Default 约束, 而 Idle 是单元变体,任何 T 都该有默认状态。

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: PartialEq> PartialEq for LoadState<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for LoadState<T>

Auto Trait Implementations§

§

impl<T> !Send for LoadState<T>

§

impl<T> !Sync for LoadState<T>

§

impl<T> Freeze for LoadState<T>
where Rc<T>: Freeze, Option<Rc<T>>: Freeze,

§

impl<T> RefUnwindSafe for LoadState<T>

§

impl<T> Unpin for LoadState<T>
where Rc<T>: Unpin, Option<Rc<T>>: Unpin,

§

impl<T> UnsafeUnpin for LoadState<T>

§

impl<T> UnwindSafe for LoadState<T>
where Rc<T>: UnwindSafe, Option<Rc<T>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.