Skip to main content

OptionType

Trait OptionType 

Source
pub trait OptionType:
    Sized
    + Clone
    + Send
    + Sync
    + 'static {
Show 13 methods // Required methods fn parse(s: &str) -> Result<Self, String>; fn format(&self) -> String; fn type_label() -> &'static str; // Provided methods fn enumerate() -> Option<Vec<&'static str>> { ... } fn enumerate_with_docs() -> Option<Vec<EnumeratedValue>> { ... } fn name_forms(_canonical: &str) -> Vec<String> { ... } fn is_bool() -> bool { ... } fn accepts_list() -> bool { ... } fn try_negation_value() -> Result<Self, String> { ... } fn enumerate_is_exhaustive() -> bool { ... } fn schema() -> ConfigSchema { ... } fn to_value(&self) -> ConfigValue { ... } fn from_value(value: &ConfigValue) -> Result<Self, String> { ... }
}
Expand description

Surface contract for any value a typed crate::option::Option can hold. Implementors describe how their type round-trips through the user-facing :set foo=value syntax.

Required Methods§

Source

fn parse(s: &str) -> Result<Self, String>

Parse the right-hand side of :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

Render the current value back to a string (:set foo? echo, the customize buffer view, value comparison). Round-trips with Self::parse.

Source

fn type_label() -> &'static str

Short type label for :describe-option ("boolean", "foldmethod", etc.). Used in help bodies and the customize buffer view.

Provided Methods§

Source

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

Optional: enumerate valid string forms for :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>>

Optional: enumerate valid string forms WITH per-value doc strings for the cmdline-completion marginalia column. Default impl wraps Self::enumerate with empty docs; types with rich help override.

Slice 3c.unify.option-doc-annotator: cmdline completion surfaces these as right-aligned marginalia. Example (foldmethod): marker Fold by markers ({{{...}}}) indent Fold by indent level manual User-defined folds only syntax Folds from tree-sitter syntax tree

Source

fn name_forms(_canonical: &str) -> Vec<String>

Optional: alternative name forms this type accepts for the option name itself. Used by completion to surface the name alongside its negation (:set nu / :set nonu). Default: no extra forms. Booleans return [format!("no{canonical}")].

Source

fn is_bool() -> bool

Whether this type’s option supports :set noFOO. bool returns true; everything else false. Drives the negate path in the cmdline parser.

Source

fn accepts_list() -> bool

Whether this option’s value is list-shaped — i.e. a TOML array at config-load time should be joined into the delimited string 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>

Negation value (only meaningful for 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

Whether Self::enumerate is the COMPLETE set of valid values (a closed enum) or a completion hint over an open space.

Default false, and the default is the point. Self::enumerate’s contract is “enumerate valid string forms for :set foo=<Tab> completion”, which several types read as a hint: crate::ModelineZone advertises auto while accepting any comma-separated list, crate::ExpandHeight advertises half/full while also accepting a bare number, and crate::RootMarkers advertises the default markers while accepting any of them. That ambiguity was harmless while enumerate only fed a completion popup; TC.1 gave it a second consumer that draws a conclusion from it, so it has to be named.

Deriving the schema from enumerate alone would have described three open-ended types as closed sets, and :customize would then offer a picker of one value for an option that accepts arbitrary lists. Opting IN is one line per type and cannot be wrong by omission.

Source

fn schema() -> ConfigSchema

The declared shape of this type’s values.

Default: enum(...) for a type whose enumeration is closed (Self::enumerate_is_exhaustive), else scalar(string) — the honest description of a type whose only contract is parse/format.

Source

fn to_value(&self) -> ConfigValue

This value as a schema-shaped tree.

Default: the format() string, which matches the default schema(). MUST agree with schema() — a type that overrides one and not the other is a silently lossy option, which is what the round-trip test in this module exists to catch.

Source

fn from_value(value: &ConfigValue) -> Result<Self, String>

Rebuild from a tree. Default: the inverse of Self::to_value, deferring to parse so a type’s validation rules apply on this path exactly as they do on :set.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl OptionType for AutoWrap

Source§

fn enumerate_is_exhaustive() -> bool

Closed: parse accepts the three canonical labels plus the boolean-ish aliases, and nothing else — so :customize offers a picker rather than a text field.

Source§

fn parse(s: &str) -> Result<Self, String>

Source§

fn format(&self) -> String

Source§

fn type_label() -> &'static str

Source§

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

Source§

fn enumerate_with_docs() -> Option<Vec<EnumeratedValue>>

Source§

impl OptionType for BufferDisplayPreference

Source§

fn enumerate_is_exhaustive() -> bool

TC.1: closed — parse accepts these forms and nothing else, so the schema is an enum and :customize can offer a picker.

Source§

fn parse(s: &str) -> Result<Self, String>

Source§

fn format(&self) -> String

Source§

fn type_label() -> &'static str

Source§

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

Source§

fn enumerate_with_docs() -> Option<Vec<EnumeratedValue>>

Source§

impl OptionType for FoldMethod

Source§

fn enumerate_is_exhaustive() -> bool

TC.1: closed — parse accepts these forms and nothing else, so the schema is an enum and :customize can offer a picker.

Source§

fn parse(s: &str) -> Result<Self, String>

Source§

fn format(&self) -> String

Source§

fn type_label() -> &'static str

Source§

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

Source§

fn enumerate_with_docs() -> Option<Vec<EnumeratedValue>>

Source§

impl OptionType for IndentMethod

Source§

fn enumerate_is_exhaustive() -> bool

TC.1: closed — parse accepts these forms and nothing else, so the schema is an enum and :customize can offer a picker.

Source§

fn parse(s: &str) -> Result<Self, String>

Source§

fn format(&self) -> String

Source§

fn type_label() -> &'static str

Source§

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

Source§

fn enumerate_with_docs() -> Option<Vec<EnumeratedValue>>

Source§

impl OptionType for ProviderChain

Source§

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

The bare rungs only. external: and plugin: carry a payload, so they cannot be completion candidates — offering external: alone would complete to a value that fails to parse.

Source§

fn enumerate_is_exhaustive() -> bool

Open, unlike every other enumerated option here: the value is a list, and two of its rungs take arbitrary payloads. A :customize picker over these three forms would be actively wrong — it would hide external: and offer no way to write a chain of more than one.

Source§

fn parse(s: &str) -> Result<Self, String>

Source§

fn format(&self) -> String

Source§

fn type_label() -> &'static str

Source§

impl OptionType for String

Source§

impl OptionType for TablineShow

Source§

fn enumerate_is_exhaustive() -> bool

TC.1: closed — parse accepts these forms and nothing else, so the schema is an enum and :customize can offer a picker.

Source§

fn parse(s: &str) -> Result<Self, String>

Source§

fn format(&self) -> String

Source§

fn type_label() -> &'static str

Source§

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

Source§

fn enumerate_with_docs() -> Option<Vec<EnumeratedValue>>

Source§

impl OptionType for ZoomIndicator

Source§

fn enumerate_is_exhaustive() -> bool

Closed — parse accepts these four forms and nothing else, so :customize can offer a picker rather than a free-text field.

Source§

fn parse(s: &str) -> Result<Self, String>

Source§

fn format(&self) -> String

Source§

fn type_label() -> &'static str

Source§

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

Source§

fn enumerate_with_docs() -> Option<Vec<EnumeratedValue>>

Source§

impl OptionType for bool

Source§

impl OptionType for i64

Implementors§

Source§

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§

impl OptionType for Decorations

Source§

impl OptionType for DiagnosticsInline

Source§

impl OptionType for DiagnosticsSeverity

Source§

impl OptionType for ExpandHeight

Source§

impl OptionType for ModelineZone

Source§

impl OptionType for PluginTraceLevel

Source§

impl OptionType for RootMarkers

Source§

impl OptionType for SignColumn