Skip to main content

ConfigSchema

Enum ConfigSchema 

Source
pub enum ConfigSchema {
    Scalar(ScalarKind),
    Enum(Vec<String>),
    List(Box<ConfigSchema>),
    Record(Vec<SchemaField>),
}
Expand description

The declared shape of an option’s value.

Enum is not sugar for Scalar(Str): it is the difference between :customize offering a picker and offering a text field. It is derived from OptionType::enumerate, but only for a type that declares that enumeration CLOSED (enumerate_is_exhaustive) — several types use enumerate as a completion hint over an open space, and describing those as enums would be worse than describing them as strings.

Variants§

§

Scalar(ScalarKind)

A single boolean, integer or string.

§

Enum(Vec<String>)

A closed set of string forms. Carries the forms in declaration order — completion and :customize both show them in the order the type meant.

§

List(Box<ConfigSchema>)

A homogeneous list; every element has the inner shape.

§

Record(Vec<SchemaField>)

A fixed set of named fields. Unknown fields are a validation error, not ignored.

Implementations§

Source§

impl ConfigSchema

Source

pub fn string() -> Self

Shorthand constructors, because the common shapes are written often enough that ConfigSchema::Scalar(ScalarKind::Str) becomes noise. This one is Scalar(Str).

§Examples
use lattice_config::{ConfigSchema, SchemaField};

let template = ConfigSchema::record([
    SchemaField::new("key", ConfigSchema::string(), "Selection key"),
    SchemaField::new("empty", ConfigSchema::bool(), "Start empty").optional(),
]);
let schema = ConfigSchema::list(template);
assert!(schema.is_composite());
assert_eq!(schema.label(), "list<record>");
assert_eq!(ConfigSchema::int().label(), "integer");
Source

pub fn int() -> Self

Scalar(Int).

Source

pub fn bool() -> Self

Scalar(Bool).

Source

pub fn list(inner: ConfigSchema) -> Self

A list whose every element has shape inner.

Source

pub fn record(fields: impl IntoIterator<Item = SchemaField>) -> Self

A record with fields, in declaration order (the order :customize renders them; validation does not depend on it).

Source

pub fn is_composite(&self) -> bool

Whether this shape has anything below its top level. The line the TOML loader and :describe-option branch on: a scalar-shaped option keeps every path it has today, a composite one takes the tree path.

Source

pub fn label(&self) -> String

A one-line rendering for :describe-option’s type column (list<record>, enum, string). The full field-by-field rendering is TC.8’s; this is what fits where type_label() used to go.

Source§

impl ConfigSchema

Source

pub fn describe(&self) -> Option<Vec<String>>

The shape, written out for :describe-option.

Lives here rather than in the help builder because it is a property of the schema, and the alternative is a walk over ConfigSchema’s variants in a crate that does not own them — which is the arrangement that goes stale the first time a variant is added.

Returns None for a shape that says nothing a reader does not already know from the type label: a bare scalar. :describe-option already prints type: integer and a block underneath repeating it is noise.

An enum renders even though values: already lists its forms, because the two answer different questions once nesting exists — values: is flat, and a list-of-enum has forms that belong to the ELEMENT.

Trait Implementations§

Source§

impl Clone for ConfigSchema

Source§

fn clone(&self) -> ConfigSchema

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 ConfigSchema

Source§

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

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

impl Eq for ConfigSchema

Source§

impl PartialEq for ConfigSchema

Source§

fn eq(&self, other: &ConfigSchema) -> 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 ConfigSchema

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> 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.
§

impl<T> WithSubscriber for T

§

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
§

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

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