pub struct FormState<V> { /* private fields */ }Expand description
表单状态。V 通常是 String / 数值等字段值。
Implementations§
Source§impl<V: Clone + PartialEq> FormState<V>
impl<V: Clone + PartialEq> FormState<V>
pub fn new(initial: impl IntoIterator<Item = (impl Into<String>, V)>) -> Self
pub fn draft(&self, field: &str) -> Option<&V>
pub fn draft_all(&self) -> &BTreeMap<String, V>
pub fn error(&self, field: &str) -> Option<&str>
pub fn errors(&self) -> &BTreeMap<String, String>
pub fn submit_state(&self) -> &SubmitState
pub fn submit_error(&self) -> Option<&'static str>
pub fn edit_generation(&self) -> u64
pub fn is_dirty(&self) -> bool
Sourcepub fn edit(&mut self, field: impl Into<String>, value: V) -> bool
pub fn edit(&mut self, field: impl Into<String>, value: V) -> bool
编辑字段:只 bump edit_generation,不触碰 submit / submit_error。
返回 true 表示值确实变化。
Sourcepub fn set_errors(&mut self, errors: BTreeMap<String, String>) -> bool
pub fn set_errors(&mut self, errors: BTreeMap<String, String>) -> bool
应用校验结果。只写 errors,不影响 submit 状态 —— 校验失败不覆盖 mutation 失败。
返回 true 表示错误集合变化。
pub fn clear_errors(&mut self) -> bool
Sourcepub fn submit(&mut self, generation: u64) -> Option<u64>
pub fn submit(&mut self, generation: u64) -> Option<u64>
提交。校验未通过时拒绝进入 Pending(调用方应先 set_errors)。
返回 None 表示被拒绝或 pending 去重;Some(generation) 用于回投。
pub fn succeed(&mut self, generation: u64) -> bool
pub fn fail(&mut self, generation: u64, message: &'static str) -> bool
Sourcepub fn acknowledge(&mut self) -> bool
pub fn acknowledge(&mut self) -> bool
成功后重置到 Idle,保留草稿值(用户可继续编辑同一表单)。
Trait Implementations§
impl<V: PartialEq> StructuralPartialEq for FormState<V>
Auto Trait Implementations§
impl<V> Forget for FormState<V>
impl<V> Freeze for FormState<V>
impl<V> Move for FormState<V>
impl<V> RefUnwindSafe for FormState<V>where
V: RefUnwindSafe,
impl<V> Send for FormState<V>
impl<V> Sync for FormState<V>
impl<V> Unpin for FormState<V>
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>where
BTreeMap<String, V>: UnwindSafe,
BTreeMap<String, String>: UnwindSafe,
&'static str: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more