pub struct Option<T: OptionType> { /* private fields */ }Expand description
A typed config option. The user-visible name + metadata,
plus the cell holding the current value. Constructed once and
handed to crate::ConfigRegistry::register, which returns a
typed OptionHandle consumers use to read / write.
Implementations§
Source§impl<T: OptionType> Option<T>
impl<T: OptionType> Option<T>
Sourcepub fn new(
name: impl Into<Cow<'static, str>>,
default: T,
doc: impl Into<Cow<'static, str>>,
) -> Self
pub fn new( name: impl Into<Cow<'static, str>>, default: T, doc: impl Into<Cow<'static, str>>, ) -> Self
Build a typed option with a default value. Most options use
the OptionBuilder (see Option::builder) instead so
optional fields don’t need defaults restated.
Sourcepub fn builder(
name: impl Into<Cow<'static, str>>,
default: T,
doc: impl Into<Cow<'static, str>>,
) -> OptionBuilder<T>
pub fn builder( name: impl Into<Cow<'static, str>>, default: T, doc: impl Into<Cow<'static, str>>, ) -> OptionBuilder<T>
Builder entry point.
§Examples
use lattice_config::ErasedOption;
use lattice_config::option::Option;
let opt = Option::<i64>::builder("width", 8, "Tab visual width.")
.aliases(&["wd"])
.validate(|i| {
(1..=32).contains(i).then_some(()).ok_or_else(|| format!("out of range: {i}"))
})
.build();
assert_eq!(*opt.get(), 8);
assert_eq!(opt.set(99), Err("out of range: 99".to_string()));
opt.set(2).unwrap();
// The erased view formats; the default is captured at build time.
assert_eq!(opt.get_formatted(), "2");
assert_eq!(opt.default_formatted(), "8");Sourcepub fn structured(
name: impl Into<Cow<'static, str>>,
schema: ConfigSchema,
default: T,
doc: impl Into<Cow<'static, str>>,
) -> Self
pub fn structured( name: impl Into<Cow<'static, str>>, schema: ConfigSchema, default: T, doc: impl Into<Cow<'static, str>>, ) -> Self
TC.3: an option whose shape is declared rather than derived — the plugin-contributed structured option.
default is NOT validated here; the caller
(config_host::register_structured_option) checks it against schema
first, so a declaration that does not fit registers nothing at all
rather than producing an option that exists and cannot hold a legal
value.
Sourcepub fn declared_schema(&self) -> ConfigSchema
pub fn declared_schema(&self) -> ConfigSchema
The option’s declared shape: what was given to Self::structured, or
the type’s own crate::OptionType::schema.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Borrows the option’s name. PL8.F: was -> &'static str when the field was
a leaked &'static str; a Cow field can only lend a &str bound to
&self, so callers that need an owned name .to_owned() it (registry).
Sourcepub fn get(&self) -> Arc<T> ⓘ
pub fn get(&self) -> Arc<T> ⓘ
Wait-free read of the current value. The returned Arc<T>
is stable for the caller’s frame; concurrent writers may
publish a newer value, observed by the next call.
Trait Implementations§
Source§impl<T: OptionType> ErasedOption for Option<T>
impl<T: OptionType> ErasedOption for Option<T>
Source§fn name(&self) -> &str
fn name(&self) -> &str
tabstop, ui.diagnostics.inline). The name
crate::ConfigRegistry keys failures and events under, even
when the user typed an alias.Source§fn aliases(&self) -> &'static [&'static str]
fn aliases(&self) -> &'static [&'static str]
ts for
tabstop). Empty for most options.Source§fn type_label(&self) -> &'static str
fn type_label(&self) -> &'static str
Source§fn parse_and_set(&self, value: &str) -> Result<(), String>
fn parse_and_set(&self, value: &str) -> Result<(), String>
value against the option’s OptionType, run the
post-parse validator, store the new value. Returns the
concatenated error if either stage fails.Source§fn parse_to_erased(
&self,
value: &str,
) -> Result<Arc<dyn Any + Send + Sync>, String>
fn parse_to_erased( &self, value: &str, ) -> Result<Arc<dyn Any + Send + Sync>, String>
value against the option’s OptionType and run the
validator, but do not write to the option’s storage. Returns
the typed value erased as Arc<dyn Any + Send + Sync>. Used by
ConfigRegistry::parse_for_buffer_local to produce an
OptionOverride for the buffer-local layer (BL.1) without
touching the global registry.Source§fn get_formatted(&self) -> String
fn get_formatted(&self) -> String
:set foo? echo, customize
buffer view).Source§fn default_formatted(&self) -> &str
fn default_formatted(&self) -> &str
:describe-option to show
“default: X” alongside “current: Y”.Source§fn enumerate_values(&self) -> Option<Vec<&'static str>>
fn enumerate_values(&self) -> Option<Vec<&'static str>>
:set foo=<Tab>. None
means free-form (no completion).Source§fn enumerate_values_with_docs(&self) -> Option<Vec<EnumeratedValue>>
fn enumerate_values_with_docs(&self) -> Option<Vec<EnumeratedValue>>
3c.unify.option-doc-annotator — drives the
marginalia column on :set foo=<Tab> completion. None
means free-form. Default impl wraps enumerate_values
with empty docs; rich-help types override on
OptionType::enumerate_with_docs.Source§fn name_forms(&self) -> Vec<String>
fn name_forms(&self) -> Vec<String>
noNAME for
booleans). Drives :set <Tab> enumeration.Source§fn is_bool(&self) -> bool
fn is_bool(&self) -> bool
:set noNAME. Booleans true,
everything else false.Source§fn accepts_list(&self) -> bool
fn accepts_list(&self) -> bool
true) or rejected as a scalar/array mismatch (false).
Forwards to OptionType::accepts_list.Source§fn negate(&self) -> Result<(), String>
fn negate(&self) -> Result<(), String>
Self::is_bool is true). Used by the :set noNAME path.
Returns Err if called on a non-bool option (registry
guards this; this is defense in depth).Source§fn format_erased_value(
&self,
value: &Arc<dyn Any + Send + Sync>,
) -> Option<String>
fn format_erased_value( &self, value: &Arc<dyn Any + Send + Sync>, ) -> Option<String>
:set name?) to display the resolved value
when the concrete type isn’t known at the call site. Returns
None if value doesn’t downcast to this option’s Value type
(caller falls back to get_formatted() in that case).Source§fn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Source§fn current_value_erased(&self) -> Arc<dyn Any + Send + Sync> ⓘ
fn current_value_erased(&self) -> Arc<dyn Any + Send + Sync> ⓘ
Arc<dyn Any + Send + Sync>. Used by
crate::ConfigRegistry::bootstrap_resolved_with_current_values
to seed the crate::ResolvedOptions cache with each
option’s current registry value (resolution layer 5)
before mode/buffer-local layers overlay on top.