Skip to main content

RecordForm

Trait RecordForm 

Source
pub trait RecordForm:
    Sized
    + FormFields
    + Send
    + 'static
where Self::Field: Copy + Eq + Hash + Debug + Send + Sync + 'static,
{ type Model: Model + IntoExpr<Self::Model> + Send + Sync + 'static; const HAS_FORM: bool = true; // Required methods fn fields() -> Vec<FormField<Self::Field>>; fn control(field: Self::Field) -> Schema<Self>; fn hydrate(cx: &Cx, record: &Self::Model) -> FormValues; fn parse(cx: &Cx, values: &FormValues) -> Result<Self, Vec<FieldError>>; fn into_create(self) -> <Self::Model as Model>::Create; fn into_update<'a>( self, record: &'a mut Self::Model, named: &HashSet<Self::Field>, ) -> Option<<Self::Model as Model>::Update<'a>>; fn exec_update<'a>( update: <Self::Model as Model>::Update<'a>, ex: &'a mut dyn Executor, ) -> impl Future<Output = Result<(), Error>> + Send + 'a; // Provided methods fn includes() -> Includes<Self::Model> { ... } fn links(&self) -> Vec<(Self::Field, Vec<String>)> { ... } }
Expand description

The typed value a resource’s form submission parses into.

Derive it from a model with tablo_core::ModelForm or from a struct with tablo_core::RecordForm; a hand-written impl is what the derives expand to.

Its FormFields are one variant per form field, the key Posted and a refusal use, whose bound form keys are Self::fields’.

Provided Associated Constants§

Source

const HAS_FORM: bool = true

Whether the resource naming this form has create and edit pages.

Panel::resource registers the create, edit, and options routes only when this holds. NoForm sets it to false.

Required Associated Types§

Source

type Model: Model + IntoExpr<Self::Model> + Send + Sync + 'static

The model the form writes.

Required Methods§

Source

fn fields() -> Vec<FormField<Self::Field>>

Every field, in declaration order, with the keys it binds.

Source

fn control(field: Self::Field) -> Schema<Self>

The control the form renders field with when its form does not place it: what controls() hands over for the field, as a one-control schema.

A resource’s form renders every field it does not place after the ones it does, in declaration order, so a resource that declares no form renders one control per field.

Source

fn hydrate(cx: &Cx, record: &Self::Model) -> FormValues

The stored record as the form spells it.

Source

fn parse(cx: &Cx, values: &FormValues) -> Result<Self, Vec<FieldError>>

Parse a completed submission: the form’s only presence and type check.

§Errors

Every key that failed, each once, under one of Self::fields’ keys.

Source

fn into_create(self) -> <Self::Model as Model>::Create

The create builder with every field set.

Source

fn into_update<'a>( self, record: &'a mut Self::Model, named: &HashSet<Self::Field>, ) -> Option<<Self::Model as Model>::Update<'a>>

The instance update builder with one assignment per named field, or None when no field is named.

None is what keeps a submission that names no field from building an empty update, which toasty refuses with an assertion.

Source

fn exec_update<'a>( update: <Self::Model as Model>::Update<'a>, ex: &'a mut dyn Executor, ) -> impl Future<Output = Result<(), Error>> + Send + 'a

Execute a builder Self::into_update returned.

Toasty’s instance update builder implements no trait that carries exec, so the generic write reaches it through the form.

Provided Methods§

Source

fn includes() -> Includes<Self::Model>

The relations hydrate reads off the record: each many-to-many field’s, which the edit page and the edit’s write load the record with.

The records each many-to-many field holds, as their keys’ form spelling: what write_create links a new record to, and what write_update leaves a posted field’s record linked to.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<M> RecordForm for NoForm<M>
where M: Model + IntoExpr<M> + Send + Sync + 'static,

Source§

const HAS_FORM: bool = false

Source§

type Model = M