Skip to main content

QueryState

Struct QueryState 

Source
pub struct QueryState<T> { /* private fields */ }
Expand description

query 状态机。T 通常是 Vec<Row> / Rc<Vec<Item>> 这类可共享快照。

Implementations§

Source§

impl<T> QueryState<T>

Source

pub fn new(key: QueryKey) -> Self

Source

pub fn seed(&mut self, key: QueryKey, value: Rc<T>)

用缓存快照恢复状态;不 bump generation、不产生在途请求。 换 key 时重置为 Idle 后再写入,避免旧 key 的 phase 泄漏到新 key。

Source

pub fn key(&self) -> QueryKey

Source

pub fn generation(&self) -> u64

Source

pub fn is_pending(&self) -> bool

Source

pub fn phase(&self) -> &QueryPhase<T>

Source

pub fn load_state(&self) -> Option<&LoadState<T>>

Source

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

最后已知数据(Ready / Refreshing / Failed 带数据 / Stale / Cancelled)。

Source

pub fn request(&mut self, key: QueryKey) -> Option<QueryTicket>

发起请求。相同 key 已有在途请求时返回 None(去重),不 bump generation。 成功发起返回 QueryTicket,调用方把它交给异步任务并在回投时带回。

Source

pub fn succeed(&mut self, ticket: QueryTicket, value: T) -> bool

成功回投。ticket 的 generation 与当前一致才接受;陈旧结果丢弃。 返回 true 表示状态实际变化,调用方可据此请求重绘。

Source

pub fn fail(&mut self, ticket: QueryTicket, message: impl Into<Rc<str>>) -> bool

失败回投。同样按 generation 丢弃迟到错误;保留上一次成功数据。

Source

pub fn cancel(&mut self) -> bool

取消在途请求。bump generation 后,已发出的回调会因 generation 不匹配被丢弃。 无在途请求时是 no-op(不 bump),避免无意义地使缓存失效。

Trait Implementations§

Source§

impl<T: Clone> Clone for QueryState<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 QueryState<T>

Source§

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

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

impl<T> Default for QueryState<T>

Source§

fn default() -> Self

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

impl<T: PartialEq> PartialEq for QueryState<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 QueryState<T>

Auto Trait Implementations§

§

impl<T> !Send for QueryState<T>

§

impl<T> !Sync for QueryState<T>

§

impl<T> Forget for QueryState<T>

§

impl<T> Freeze for QueryState<T>
where QueryPhase<T>: Freeze,

§

impl<T> Move for QueryState<T>

§

impl<T> RefUnwindSafe for QueryState<T>

§

impl<T> Unpin for QueryState<T>
where QueryPhase<T>: Unpin,

§

impl<T> UnsafeUnpin for QueryState<T>

§

impl<T> UnwindSafe for QueryState<T>

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.