Skip to main content

ScalarField

Struct ScalarField 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn with_validator(self, validator: FieldValidator) -> Self

Attach an application validator with an explicit semantic revision.

See FieldValidator for the revision contract.

Source

pub fn id(&self) -> &str

The stable field ID.

Source

pub fn prompt(&self) -> &str

The human wording (cosmetic).

Source

pub fn kind(&self) -> ScalarKind

The answer kind (semantic).

Source

pub fn is_optional(&self) -> bool

Whether a blank answer without a default means omission rather than a missing value.

Source

pub fn default(&self) -> Option<&str>

The declared static default, if any (semantic).

Source

pub fn dynamic_default(&self) -> Option<&DynamicDefault>

The declared dynamic default, if any (its revision is semantic).

Source

pub fn constraint(&self) -> Option<&Constraint>

The declared constraint, if any (semantic).

Source

pub fn condition(&self) -> Option<&Condition>

The conditional-applicability rule, if any (semantic).

Source

pub fn validator(&self) -> Option<&FieldValidator>

The attached application validator, if any (its revision is semantic).

Trait Implementations§

Source§

impl Clone for ScalarField

Source§

fn clone(&self) -> ScalarField

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ScalarField

Source§

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

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

impl Eq for ScalarField

Source§

impl From<ScalarField> for Item

Source§

fn from(field: ScalarField) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ScalarField

Source§

fn eq(&self, other: &ScalarField) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ScalarField

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.