Skip to main content

ClosedValues

Enum ClosedValues 

Source
pub enum ClosedValues {
    Static(&'static [&'static str]),
    Owned(Vec<String>),
}
Expand description

A closed set of valid values for a flag. Both static (&'static [&'static str]) and runtime-owned (Vec<String>) variants are supported via the same query API.

Solves two TODO gaps in one type:

  • Item 1 (no per-set glue functions): callers no longer need to write fn palette_provider(...) -> Vec<String> { palette.iter() .filter(...).collect() } boilerplate per closed set. Just construct a ClosedValues and convert to a ValueProvider via ClosedValues::into_provider.
  • Item 5 (validation surface): the same declaration that drives completion can drive parser-side validation — ClosedValues::validate returns true for any value the completer would have offered.
use veks_completion::ClosedValues;

let metrics = ClosedValues::Static(&["L2", "IP", "COSINE"]);

// Completion: prefix-filtered.
assert_eq!(metrics.complete(""), vec!["L2", "IP", "COSINE"]);
assert_eq!(metrics.complete("CO"), vec!["COSINE"]);

// Validation: exact set membership.
assert!(metrics.validate("L2"));
assert!(!metrics.validate("bogus"));

// Convert to a ValueProvider for tree registration.
let provider = metrics.clone().into_provider();
assert_eq!(provider("CO", &[]), vec!["COSINE"]);

Variants§

§

Static(&'static [&'static str])

Borrowed &'static slice — preferred when the set is known at compile time (the common case).

§

Owned(Vec<String>)

Heap-owned values — for runtime-built specs whose closed set isn’t known until the binary inspects its environment.

Implementations§

Source§

impl ClosedValues

Source

pub fn values(&self) -> Vec<&str>

Iterate over the values as &str regardless of variant.

Source

pub fn complete(&self, partial: &str) -> Vec<String>

Prefix-filtered completion candidates.

Source

pub fn validate(&self, value: &str) -> bool

Membership check — true iff value is in the set.

Source

pub fn into_provider(self) -> ValueProvider

Wrap as a ValueProvider for use with Node::with_value_provider. The set is moved into the closure; clone the ClosedValues first if you also need to keep it for validation.

Trait Implementations§

Source§

impl Clone for ClosedValues

Source§

fn clone(&self) -> ClosedValues

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClosedValues

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<ClosedValues> for ValueProvider

Convenience: hand any ClosedValues to APIs that take a ValueProvider without explicit .into_provider().

Source§

fn from(cv: ClosedValues) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.