pub struct Schema<F = ()> { /* private fields */ }Expand description
Composes fields and layout blocks and resolves every field once into one list.
F is the record form whose controls the schema places. A resource’s form is a
Schema<UserForm>, which only UserForm::controls() fill, so a control from another form or a
field built with Field::text fails to compile there. A page’s or an action’s schema is a
plain Schema, which Field’s constructors fill.
Implementations§
Source§impl<F> Schema<F>
impl<F> Schema<F>
Sourcepub fn read(
&self,
cx: &Cx,
posted: &[(String, String)],
) -> Result<FormValues, String>
pub fn read( &self, cx: &Cx, posted: &[(String, String)], ) -> Result<FormValues, String>
Reads a posted body’s (key, value) pairs, in the order it posts them, into the values
the schema’s fields hold: a scalar control’s last value, a multiple choice’s values without
blanks or repeats, a file list’s chosen file names likewise, and a repeater’s rows in the
order its key lists them. A field that posts nothing holds nothing, so an edit keeps its
stored value. A key no field declares is left out: a page reads its own, such as the
CSRF token, from the pairs.
A text control’s value is read through its type in the request’s
time_zone: a timestamp’s control posts a wall-clock time, which reads
as the instant it names there.
A resource’s form and an action’s input read their submissions; a page handling its own post reads it before parsing it.
§Errors
A repeater’s key lists something other than its rows, a row twice, a row posting nothing,
or more than MAX_REPEATER_ROWS rows: no browser posts these,
so a handler answers 400.
Source§impl<F> Schema<F>
impl<F> Schema<F>
Sourcepub fn new(children: impl IntoSchema<F>) -> Self
pub fn new(children: impl IntoSchema<F>) -> Self
Builds a Schema from any IntoSchema and reports duplicate field names as declaration
errors.
Sourcepub fn fields(&self) -> impl Iterator<Item = &Field>
pub fn fields(&self) -> impl Iterator<Item = &Field>
Every field, in the order it joins the schema: a layout’s fields as it composes, in declaration order.
Sourcepub async fn render<'a>(
&self,
cx: &'a Cx,
source: Source<'_>,
) -> Result<BoxView<'a>>
pub async fn render<'a>( &self, cx: &'a Cx, source: Source<'_>, ) -> Result<BoxView<'a>>
Renders the schema from source and fails with declaration errors instead of rendering.
§Errors
A misdeclared schema fails with its errors rather than render.
Sourcepub fn extend(self, other: Schema<F>) -> Schema<F>
pub fn extend(self, other: Schema<F>) -> Schema<F>
Appends another schema’s nodes after this one’s.
Sourcepub fn declaration_errors(&self) -> Vec<DeclarationErrorKind>
pub fn declaration_errors(&self) -> Vec<DeclarationErrorKind>
Reports what is wrong with this declaration: a field whose lens binds no single column, and two fields sharing a name.