#[non_exhaustive]pub struct FieldRule<C> {
pub at: PathPat,
pub ty: Option<FieldType>,
pub constraint: Option<C>,
pub present: Presentation,
}Expand description
One field rule: which node(s) it governs, the type it expects, an optional
constraint of the embedder’s own type C, and how to present it.
#[non_exhaustive]: a rule gains ways to describe a field over time, so it
is built from FieldRule::new and the chainable setters rather than a
struct literal. Reading the fields is unchanged.
use fig_schema::{FieldRule, FieldType, PathPat, Presentation, Validate, Validation};
let rule = FieldRule::new(PathPat::each_item_of("audience"))
.ty(FieldType::Str)
.constraint(Vocab)
.present(Presentation::default().title("Audience"));
assert_eq!(rule.ty, Some(FieldType::Str));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.at: PathPatWhich node(s) this governs (reaches list elements, not only scalars).
ty: Option<FieldType>The expected type — drives type-directed parsing and widget choice.
constraint: Option<C>A value constraint, in whatever shape the embedder defines.
present: PresentationRenderer-neutral presentation hints.
Implementations§
Source§impl<C> FieldRule<C>
impl<C> FieldRule<C>
Sourcepub fn new(at: PathPat) -> Self
pub fn new(at: PathPat) -> Self
A rule governing at, with no type, no constraint and no presentation
hints — the parts a caller adds with the setters below.
Sourcepub fn ty(self, ty: impl Into<Option<FieldType>>) -> Self
pub fn ty(self, ty: impl Into<Option<FieldType>>) -> Self
Set the expected type. Takes a FieldType or an Option<FieldType>,
so a caller reading a config that may not declare one can pass it
straight through.
Sourcepub fn constraint(self, constraint: C) -> Self
pub fn constraint(self, constraint: C) -> Self
Set the value constraint.
This one takes a C rather than an impl Into<Option<C>> the way
FieldRule::ty does: with C otherwise unconstrained, Into cannot
tell C from Option<C> and the call fails to infer. Use
FieldRule::constraint_opt for a constraint that may be absent.
Sourcepub fn constraint_opt(self, constraint: Option<C>) -> Self
pub fn constraint_opt(self, constraint: Option<C>) -> Self
Set the value constraint from an optional one. None leaves the rule
imposing nothing, which is what a type-only rule wants.
Sourcepub fn present(self, present: Presentation) -> Self
pub fn present(self, present: Presentation) -> Self
Set the presentation hints.