Skip to main content

FormState

Struct FormState 

Source
pub struct FormState<V> { /* private fields */ }
Expand description

表单状态。V 通常是 String / 数值等字段值。

Implementations§

Source§

impl<V: Clone + PartialEq> FormState<V>

Source

pub fn new(initial: impl IntoIterator<Item = (impl Into<String>, V)>) -> Self

Source

pub fn draft(&self, field: &str) -> Option<&V>

Source

pub fn draft_all(&self) -> &BTreeMap<String, V>

Source

pub fn error(&self, field: &str) -> Option<&str>

Source

pub fn errors(&self) -> &BTreeMap<String, String>

Source

pub fn submit_state(&self) -> &SubmitState

Source

pub fn submit_error(&self) -> Option<&'static str>

Source

pub fn edit_generation(&self) -> u64

Source

pub fn is_dirty(&self) -> bool

Source

pub fn edit(&mut self, field: impl Into<String>, value: V) -> bool

编辑字段:只 bump edit_generation,不触碰 submit / submit_error。 返回 true 表示值确实变化。

Source

pub fn set_errors(&mut self, errors: BTreeMap<String, String>) -> bool

应用校验结果。只写 errors,不影响 submit 状态 —— 校验失败不覆盖 mutation 失败。 返回 true 表示错误集合变化。

Source

pub fn clear_errors(&mut self) -> bool

Source

pub fn submit(&mut self, generation: u64) -> Option<u64>

提交。校验未通过时拒绝进入 Pending(调用方应先 set_errors)。 返回 None 表示被拒绝或 pending 去重;Some(generation) 用于回投。

Source

pub fn succeed(&mut self, generation: u64) -> bool

Source

pub fn fail(&mut self, generation: u64, message: &'static str) -> bool

Source

pub fn acknowledge(&mut self) -> bool

成功后重置到 Idle,保留草稿值(用户可继续编辑同一表单)。

Trait Implementations§

Source§

impl<V: Clone> Clone for FormState<V>

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<V: Debug> Debug for FormState<V>

Source§

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

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

impl<V> Default for FormState<V>

Source§

fn default() -> Self

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

impl<V: PartialEq> PartialEq for FormState<V>

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<V: PartialEq> StructuralPartialEq for FormState<V>

Auto Trait Implementations§

§

impl<V> Forget for FormState<V>

§

impl<V> Freeze for FormState<V>
where *const LeafNode<String, V> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, V)>>: Freeze, *const LeafNode<String, String> is !null: Freeze, PhantomData<Box<(String, String)>>: Freeze, &'static str: Freeze,

§

impl<V> Move for FormState<V>

§

impl<V> RefUnwindSafe for FormState<V>
where V: RefUnwindSafe,

§

impl<V> Send for FormState<V>
where NodeRef<Owned, String, V, LeafOrInternal>: Send, BoxRaw<(String, V)>: Send, NodeRef<Owned, String, String, LeafOrInternal>: Send, BoxRaw<(String, String)>: Send, &'static str: Send,

§

impl<V> Sync for FormState<V>
where NodeRef<Owned, String, V, LeafOrInternal>: Sync, BoxRaw<(String, V)>: Sync, NodeRef<Owned, String, String, LeafOrInternal>: Sync, BoxRaw<(String, String)>: Sync,

§

impl<V> Unpin for FormState<V>
where *const LeafNode<String, V> is !null: Unpin, Box<(String, V)>: Unpin, *const LeafNode<String, String> is !null: Unpin, Box<(String, String)>: Unpin, &'static str: Unpin,

§

impl<V> UnsafeUnpin for FormState<V>
where *const LeafNode<String, V> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(String, V)>>: UnsafeUnpin, *const LeafNode<String, String> is !null: UnsafeUnpin, PhantomData<Box<(String, String)>>: UnsafeUnpin, &'static str: UnsafeUnpin,

§

impl<V> UnwindSafe for FormState<V>

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.