Skip to main content

ErasedOption

Trait ErasedOption 

Source
pub trait ErasedOption: Send + Sync {
Show 20 methods // Required methods fn name(&self) -> &str; fn aliases(&self) -> &'static [&'static str]; fn doc(&self) -> &str; fn type_label(&self) -> &'static str; fn parse_and_set(&self, value: &str) -> Result<(), String>; fn parse_to_erased( &self, value: &str, ) -> Result<Arc<dyn Any + Send + Sync>, String>; fn get_formatted(&self) -> String; fn default_formatted(&self) -> &str; fn enumerate_values(&self) -> Option<Vec<&'static str>>; fn enumerate_values_with_docs(&self) -> Option<Vec<EnumeratedValue>>; fn name_forms(&self) -> Vec<String>; fn is_bool(&self) -> bool; fn accepts_list(&self) -> bool; fn negate(&self) -> Result<(), String>; fn format_erased_value( &self, value: &Arc<dyn Any + Send + Sync>, ) -> Option<String>; fn as_any(&self) -> &dyn Any; fn current_value_erased(&self) -> Arc<dyn Any + Send + Sync> ⓘ; fn schema(&self) -> ConfigSchema; fn get_value(&self) -> ConfigValue; fn set_value(&self, value: &ConfigValue) -> Result<(), String>;
}
Expand description

Type-erased operations every typed Option<T> supports. The registry stores Arc<dyn ErasedOption> in a Vec indexed by the private idx field of crate::option::OptionHandle; parse_and_set_by_name drives this trait when the user types :set name=value.

as_any is the canonical Rust idiom for downcasting back to the concrete Option<T> when a typed handle reads. Required rather than auto-derived so the bound stays explicit.

Required Methods§

Source

fn name(&self) -> &str

Canonical name (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]

Alternative names that resolve to this option (ts for tabstop). Empty for most options.

Source

fn doc(&self) -> &str

Human-readable description, shown by :describe-option and :customize.

Source

fn type_label(&self) -> &'static str

The value type’s OptionType::type_label (boolean, integer, string, signcolumn, …).

Source

fn parse_and_set(&self, value: &str) -> Result<(), String>

Parse 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>

Parse 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

Render the current value (:set foo? echo, customize buffer view).

Source

fn default_formatted(&self) -> &str

Render the default value (the value the option held at registration time). Used by :describe-option to show “default: X” alongside “current: Y”.

Source

fn enumerate_values(&self) -> Option<Vec<&'static str>>

Enumerate valid string values for :set foo=<Tab>. None means free-form (no completion).

Source

fn enumerate_values_with_docs(&self) -> Option<Vec<EnumeratedValue>>

Enumerate valid string values + per-value doc strings. Slice 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>

Alternate name forms the cmdline accepts (noNAME for booleans). Drives :set <Tab> enumeration.

Source

fn is_bool(&self) -> bool

Whether this option supports :set noNAME. Booleans true, everything else false.

Source

fn accepts_list(&self) -> bool

Whether this option’s value is list-shaped (ML.5). The config loader consults this to decide whether a TOML array for this key should be joined into the option’s delimited parse form (true) or rejected as a scalar/array mismatch (false). Forwards to OptionType::accepts_list.

Source

fn negate(&self) -> Result<(), String>

Set the option to its negation value (only meaningful when 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>

Format an already-erased value of this option’s type. Used by the query echo path (: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

Project back to the concrete type for typed-handle reads.

Implementors return self. Crate-private trait methods can’t be expressed cleanly across the boundary, so we keep this in the public surface but document it as implementation-detail.

Source

fn current_value_erased(&self) -> Arc<dyn Any + Send + Sync> ⓘ

Return the option’s current value as an erased 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.

Source

fn schema(&self) -> ConfigSchema

This option’s declared shape.

Source

fn get_value(&self) -> ConfigValue

The current value as a schema-shaped tree.

Source

fn set_value(&self, value: &ConfigValue) -> Result<(), String>

Validate value against Self::schema, then commit it.

Validation runs against the SCHEMA first, so the error carries a path (target.file: expected string, got integer), and only then through the type’s own conversion and post-parse validator — the same two stages parse_and_set runs, in the same order, so the tree path and the string path cannot disagree about whether a value is acceptable.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§