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§
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 hydrate(cx: &Cx, record: &Self::Model) -> HashMap<String, String>
fn hydrate(cx: &Cx, record: &Self::Model) -> HashMap<String, String>
The stored record as the form spells it.
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 schema() -> Schema
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.
Sourcefn table() -> Table<Self::Model>
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".