pub struct ScalarField { /* private fields */ }Expand description
One scalar question in a questionnaire.
The id is the stable machine identity rendered as the line-terminal
tag (<id:project.name>); the prompt is human wording and may be
edited freely without affecting compatibility. Everything else — kind,
optionality, default (static value or dynamic-default revision),
constraint, condition, and validator revision — is semantic.
Implementations§
Source§impl ScalarField
impl ScalarField
Sourcepub fn new(
id: impl Into<String>,
prompt: impl Into<String>,
kind: ScalarKind,
) -> Self
pub fn new( id: impl Into<String>, prompt: impl Into<String>, kind: ScalarKind, ) -> Self
Create a required scalar field with a stable id, human prompt
wording, and answer kind.
The id and all declared properties are validated when the field is
passed to Questionnaire::new, not here.
Sourcepub fn optional(self) -> Self
pub fn optional(self) -> Self
Mark this field as optional (a blank answer without a default means omission rather than a missing-value error).
Optionality is semantic: it changes the fingerprint.
Sourcepub fn with_default(self, default: impl Into<String>) -> Self
pub fn with_default(self, default: impl Into<String>) -> Self
Declare a static default value.
The renderer pre-fills the default as the answer text below the question line, and during decoding any blank answer resolves to the default before optionality is considered. Defaults must be a single line with no outer whitespace (parsed answers are trimmed) and must themselves decode cleanly. Defaults are semantic: they change the fingerprint. A field declares either a static default or a dynamic one, never both.
Sourcepub fn with_dynamic_default(self, dynamic_default: DynamicDefault) -> Self
pub fn with_dynamic_default(self, dynamic_default: DynamicDefault) -> Self
Declare a dynamic default, computed from earlier decoded answers.
The same blank rule applies as for a static default — a blank answer
resolves through the computed default before optionality,
identically across interactive, file, and stdin collection — but the
rendered sheet leaves the answer region empty (a sheet cannot
pre-fill a value that depends on other answers), and interactive
prompting shows the computed default in the prompt message. The
declared revision is semantic and enters the fingerprint in place of
a static value; see DynamicDefault for the revision and
dependency contracts. A field declares either a static default or a
dynamic one, never both.
Sourcepub fn one_of(
self,
choices: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn one_of( self, choices: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Constrain the answer to one of the given values.
Checked after kind conversion by the shared decoder. Not applicable
to ScalarKind::Bool fields. Semantic: changes the fingerprint.
Sourcepub fn active_when(
self,
controller: impl Into<String>,
expected: impl Into<String>,
) -> Self
pub fn active_when( self, controller: impl Into<String>, expected: impl Into<String>, ) -> Self
Make this field applicable only when the earlier-declared controller
field decodes to expected.
The controller must live in the same group as this field or in one of its enclosing groups (so every submitted occurrence resolves it unambiguously); a controller inside a repeatable group gates its dependents per occurrence. An inactive field may stay blank (or keep its untouched pre-filled default) even when required; a populated inactive field is a validation error. Conditions are semantic: they change the fingerprint.
Sourcepub fn with_validator(self, validator: FieldValidator) -> Self
pub fn with_validator(self, validator: FieldValidator) -> Self
Attach an application validator with an explicit semantic revision.
See FieldValidator for the revision contract.
Sourcepub fn kind(&self) -> ScalarKind
pub fn kind(&self) -> ScalarKind
The answer kind (semantic).
Sourcepub fn is_optional(&self) -> bool
pub fn is_optional(&self) -> bool
Whether a blank answer without a default means omission rather than a missing value.
Sourcepub fn dynamic_default(&self) -> Option<&DynamicDefault>
pub fn dynamic_default(&self) -> Option<&DynamicDefault>
The declared dynamic default, if any (its revision is semantic).
Sourcepub fn constraint(&self) -> Option<&Constraint>
pub fn constraint(&self) -> Option<&Constraint>
The declared constraint, if any (semantic).
Sourcepub fn condition(&self) -> Option<&Condition>
pub fn condition(&self) -> Option<&Condition>
The conditional-applicability rule, if any (semantic).
Sourcepub fn validator(&self) -> Option<&FieldValidator>
pub fn validator(&self) -> Option<&FieldValidator>
The attached application validator, if any (its revision is semantic).
Trait Implementations§
Source§impl Clone for ScalarField
impl Clone for ScalarField
Source§fn clone(&self) -> ScalarField
fn clone(&self) -> ScalarField
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ScalarField
impl Debug for ScalarField
impl Eq for ScalarField
Source§impl From<ScalarField> for Item
impl From<ScalarField> for Item
Source§fn from(field: ScalarField) -> Self
fn from(field: ScalarField) -> Self
Source§impl PartialEq for ScalarField
impl PartialEq for ScalarField
impl StructuralPartialEq for ScalarField
Auto Trait Implementations§
impl !RefUnwindSafe for ScalarField
impl !UnwindSafe for ScalarField
impl Freeze for ScalarField
impl Send for ScalarField
impl Sync for ScalarField
impl Unpin for ScalarField
impl UnsafeUnpin for ScalarField
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more