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
impl ConfigSchema
Sourcepub fn string() -> Self
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");Sourcepub fn list(inner: ConfigSchema) -> Self
pub fn list(inner: ConfigSchema) -> Self
A list whose every element has shape inner.
Sourcepub fn record(fields: impl IntoIterator<Item = SchemaField>) -> Self
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).
Sourcepub fn is_composite(&self) -> bool
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§impl ConfigSchema
impl ConfigSchema
Sourcepub fn describe(&self) -> Option<Vec<String>>
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
impl Clone for ConfigSchema
Source§fn clone(&self) -> ConfigSchema
fn clone(&self) -> ConfigSchema
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 ConfigSchema
impl Debug for ConfigSchema
impl Eq for ConfigSchema
Source§impl PartialEq for ConfigSchema
impl PartialEq for ConfigSchema
impl StructuralPartialEq for ConfigSchema
Auto Trait Implementations§
impl Freeze for ConfigSchema
impl RefUnwindSafe for ConfigSchema
impl Send for ConfigSchema
impl Sync for ConfigSchema
impl Unpin for ConfigSchema
impl UnsafeUnpin for ConfigSchema
impl UnwindSafe for ConfigSchema
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.