pub enum ConfigValue {
Bool(bool),
Int(i64),
Str(String),
List(Vec<ConfigValue>),
Record(BTreeMap<String, ConfigValue>),
}Expand description
A value shaped by a ConfigSchema.
Record is a BTreeMap rather than a Vec<(String, ConfigValue)> so two
values that differ only in field order compare equal — an option’s value
arriving from lattice.toml (which does not preserve order across a
round-trip) and the same value built in init.rs must not be two different
values. The wire form is an association list, because WIT has no map; the
conversion is where the ordering stops mattering.
Variants§
Bool(bool)
A boolean leaf.
Int(i64)
An integer leaf.
Str(String)
A string leaf — also the representation of an
ConfigSchema::Enum form.
List(Vec<ConfigValue>)
A list of values (homogeneous only if its schema says so).
Record(BTreeMap<String, ConfigValue>)
Named fields, compared order-independently.
Implementations§
Source§impl ConfigValue
impl ConfigValue
Sourcepub fn record(fields: impl IntoIterator<Item = (String, ConfigValue)>) -> Self
pub fn record(fields: impl IntoIterator<Item = (String, ConfigValue)>) -> Self
Build a record from pairs. The wire and TOML forms both arrive as pairs.
Sourcepub fn kind_label(&self) -> &'static str
pub fn kind_label(&self) -> &'static str
The word a mismatch message uses for what was actually found.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Read a scalar back out. None on a kind mismatch rather than a panic —
callers are usually walking a tree they have already validated, and the
ones that have not should not be able to crash the editor over a config
file. This one reads a ConfigValue::Str.
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
The boolean in a ConfigValue::Bool; None for any other kind.
Sourcepub fn as_int(&self) -> Option<i64>
pub fn as_int(&self) -> Option<i64>
The integer in a ConfigValue::Int; None for any other kind.
Sourcepub fn as_list(&self) -> Option<&[ConfigValue]>
pub fn as_list(&self) -> Option<&[ConfigValue]>
The elements of a ConfigValue::List; None for any other kind.
Sourcepub fn field(&self, name: &str) -> Option<&ConfigValue>
pub fn field(&self, name: &str) -> Option<&ConfigValue>
A record’s field by name. None if the field is absent or
self is not a ConfigValue::Record.
Trait Implementations§
Source§impl Clone for ConfigValue
impl Clone for ConfigValue
Source§fn clone(&self) -> ConfigValue
fn clone(&self) -> ConfigValue
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 ConfigValue
impl Debug for ConfigValue
impl Eq for ConfigValue
Source§impl OptionType for ConfigValue
TC.3 — a ConfigValue is itself an option value type.
impl OptionType for ConfigValue
TC.3 — a ConfigValue is itself an option value type.
This is what a plugin’s structured option holds. The shape is NOT here: a
plugin declares its schema at registration and it is carried on the option
spec (crate::option::Option::structured), because the schema is metadata
about the option — like its doc and its default — rather than data inside
the value. A value that carried its own schema could not survive
from_value, which is a static function with no access to the option it is
being set on.
parse / format are TOML text, which keeps the :set contract and
costs nothing: the host already has a TOML parser, so a structured option
stays settable from the command line and :set foo? still echoes something
a user can read and paste back. It also means the migration of an option
that was a TOML-in-a-string is not a break for anyone who was setting it
that way — the text they wrote still parses, it is simply now validated.
Source§fn schema() -> ConfigSchema
fn schema() -> ConfigSchema
Unknowable statically — the shape belongs to the OPTION, not the type.
Every real structured option is built through
crate::option::Option::structured, which records the declared schema
on the spec and is what ErasedOption::schema() answers with. This
fallback exists only so the trait is implementable.
Source§fn parse(s: &str) -> Result<Self, String>
fn parse(s: &str) -> Result<Self, String>
:set name=value. Errors are
surfaced verbatim through the cmdline echo, so the message
should read well to the user (mention valid forms when the
space is finite). The parser MUST round-trip with format:
T::parse(&v.format()) == Ok(v) for every v.Source§fn format(&self) -> String
fn format(&self) -> String
:set foo? echo,
the customize buffer view, value comparison). Round-trips
with Self::parse.Source§fn type_label() -> &'static str
fn type_label() -> &'static str
:describe-option ("boolean",
"foldmethod", etc.). Used in help bodies and the customize
buffer view.Source§fn to_value(&self) -> ConfigValue
fn to_value(&self) -> ConfigValue
Source§fn from_value(value: &ConfigValue) -> Result<Self, String>
fn from_value(value: &ConfigValue) -> Result<Self, String>
Self::to_value,
deferring to parse so a type’s validation rules apply on this
path exactly as they do on :set.Source§fn enumerate() -> Option<Vec<&'static str>>
fn enumerate() -> Option<Vec<&'static str>>
:set foo=<Tab>
completion. None means “free-form” (no enumerable space –
integers, file paths, free strings). The values are
&'static str to keep the completion source allocation-free
in the common case.Source§fn enumerate_with_docs() -> Option<Vec<EnumeratedValue>>
fn enumerate_with_docs() -> Option<Vec<EnumeratedValue>>
Self::enumerate with empty docs;
types with rich help override. Read moreSource§fn name_forms(_canonical: &str) -> Vec<String>
fn name_forms(_canonical: &str) -> Vec<String>
:set nu / :set nonu). Default:
no extra forms. Booleans return [format!("no{canonical}")].Source§fn is_bool() -> bool
fn is_bool() -> bool
:set noFOO. bool
returns true; everything else false. Drives the negate
path in the cmdline parser.Source§fn accepts_list() -> bool
fn accepts_list() -> bool
Self::parse accepts, rather than rejected
as “not applicable to a scalar option”. false for every
scalar type (the default); true for list types like
crate::ModelineZone. Drives loader::apply_array (ML.5).
The :set cmdline path is unaffected — it always passes a
string and never sees a TOML array.Source§fn try_negation_value() -> Result<Self, String>
fn try_negation_value() -> Result<Self, String>
Self::is_bool true).
Default: returns Err – the registry guards by checking
is_bool() first, so callers that respect the contract
won’t observe this. The bool impl returns Ok(false).Source§fn enumerate_is_exhaustive() -> bool
fn enumerate_is_exhaustive() -> bool
Self::enumerate is the COMPLETE set of valid values
(a closed enum) or a completion hint over an open space. Read moreSource§impl PartialEq for ConfigValue
impl PartialEq for ConfigValue
impl StructuralPartialEq for ConfigValue
Auto Trait Implementations§
impl Freeze for ConfigValue
impl RefUnwindSafe for ConfigValue
impl Send for ConfigValue
impl Sync for ConfigValue
impl Unpin for ConfigValue
impl UnsafeUnpin for ConfigValue
impl UnwindSafe for ConfigValue
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.