Skip to main content

Schema

Struct Schema 

Source
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>

Source

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 Schema

Source

pub fn empty() -> Self

A schema with no field: a page’s or an action’s that renders nothing. A resource’s form that places nothing is Schema::default(), which renders every control.

Source§

impl<F> Schema<F>

Source

pub fn is_empty(&self) -> bool

Reports whether this schema declares nothing to render.

Source

pub fn new(children: impl IntoSchema<F>) -> Self

Builds a Schema from any IntoSchema and reports duplicate field names as declaration errors.

Source

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.

Source

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.

Source

pub fn extend(self, other: Schema<F>) -> Schema<F>

Appends another schema’s nodes after this one’s.

Source

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.

Trait Implementations§

Source§

impl<F> Debug for Schema<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F> Default for Schema<F>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<F> IntoSchema<F> for Schema<F>

Auto Trait Implementations§

§

impl<F = ()> !RefUnwindSafe for Schema<F>

§

impl<F = ()> !UnwindSafe for Schema<F>

§

impl<F> Forget for Schema<F>

§

impl<F> Freeze for Schema<F>
where PhantomData<fn() -> F>: Freeze,

§

impl<F> Move for Schema<F>

§

impl<F> Send for Schema<F>
where PhantomData<fn() -> F>: Send,

§

impl<F> Sync for Schema<F>
where PhantomData<fn() -> F>: Sync,

§

impl<F> Unpin for Schema<F>
where PhantomData<fn() -> F>: Unpin,

§

impl<F> UnsafeUnpin for Schema<F>
where PhantomData<fn() -> F>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more