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.
use tablo_core::{Field, Schema};
let form: Schema<UserForm> = Schema::new((
UserForm::controls().name,
Field::text(User::fields().email()),
));Implementations§
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, and an embedded value’s fields when it binds.
Sourcepub fn bind(self, db: &Db) -> Self
pub fn bind(self, db: &Db) -> Self
Binds the schema’s embedded values and embedded paths to db’s app schema.
A panel binds the schemas it mounts; bind one a custom page renders before rendering it. A schema with no embedded value or path is bound from the start.
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 fold_repeaters(
&self,
values: &mut HashMap<String, String>,
) -> Result<(), String>
pub fn fold_repeaters( &self, values: &mut HashMap<String, String>, ) -> Result<(), String>
Folds each repeater’s posted rows into its own key, which
parse_items reads.
A resource’s form and an action’s input fold their submissions; a page handling its own post folds it before reading it, or the rows’ keys stay apart.
§Errors
A repeater’s key lists something other than its rows, a row posting nothing, or more than
MAX_ROWS rows: no browser posts these, so a handler answers 400.
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: an embedded value or path never bound, a field whose lens binds no single column, and two fields sharing a name.