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 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<()>> + 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.
Provided Associated Constants§
Sourceconst HAS_FORM: bool = true
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§
Required Methods§
Sourcefn fields() -> Vec<FormField<Self::Field>>
fn fields() -> Vec<FormField<Self::Field>>
Every field, in declaration order, with the keys it binds.
Sourcefn control(field: Self::Field) -> Schema<Self>
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.
Sourcefn hydrate(cx: &Cx, record: &Self::Model) -> FormValues
fn hydrate(cx: &Cx, record: &Self::Model) -> FormValues
The stored record as the form spells it.
Sourcefn parse(cx: &Cx, values: &FormValues) -> Result<Self, Vec<FieldError>>
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.
Sourcefn into_create(self) -> <Self::Model as Model>::Create
fn into_create(self) -> <Self::Model as Model>::Create
The create builder with every field set.
Sourcefn into_update<'a>(
self,
record: &'a mut Self::Model,
named: &HashSet<Self::Field>,
) -> Option<<Self::Model as Model>::Update<'a>>
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.
Sourcefn exec_update<'a>(
update: <Self::Model as Model>::Update<'a>,
ex: &'a mut dyn Executor,
) -> impl Future<Output = Result<()>> + Send + 'a
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§
Sourcefn includes() -> Includes<Self::Model>
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.
Sourcefn links(&self) -> Vec<(Self::Field, Vec<String>)>
fn links(&self) -> Vec<(Self::Field, Vec<String>)>
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".