Skip to main content

RecordForm

Trait RecordForm 

Source
pub trait RecordForm:
    Sized
    + Send
    + 'static {
    type Model: Model + IntoExpr<Self::Model> + Send + Sync + 'static;
    type Field: Copy + Eq + Hash + Debug + Send + Sync + 'static;

    const HAS_FORM: bool = true;

    // Required methods
    fn fields() -> Vec<FormField<Self::Field>>;
    fn hydrate(cx: &Cx, record: &Self::Model) -> HashMap<String, String>;
    fn parse(
        cx: &Cx,
        values: &HashMap<String, String>,
    ) -> 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<()>> + Send + 'a;

    // Provided methods
    fn schema() -> Schema { ... }
    fn table() -> Table<Self::Model> { ... }
}
Expand description

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

Derive it with tablo_core::RecordForm; a hand-written impl is what the derive expands to.

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.

Source

type Field: Copy + Eq + Hash + Debug + Send + Sync + 'static

One variant per form field: the key Posted uses. Its bound form keys are Self::fields’.

Required Methods§

Source

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

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

Source

fn hydrate(cx: &Cx, record: &Self::Model) -> HashMap<String, String>

The stored record as the form spells it.

Source

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

Parse a completed, normalized submission.

§Errors

Every key that failed, each once.

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<()>> + 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 schema() -> Schema

The form’s default schema: one control per field, in declaration order. A ResourceDef without a form renders it.

The derive chooses each control from the field (see RecordForm); the default here declares none, which is what NoForm wants.

Source

fn table() -> Table<Self::Model>

The form’s default table: one column per field a column can show, in declaration order. A ResourceDef without a table lists it.

The derive lists each text field in a sortable column, searchable over a String or Option<String>, an options field by its option’s label, and a toggle as yes or no (see RecordForm). The default here lists none, so a resource whose form lists nothing, such as one naming NoForm, declares its own.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

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

Source§

const HAS_FORM: bool = false

Source§

type Model = M

Source§

type Field = !