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 aClosedValuesand convert to aValueProviderviaClosedValues::into_provider. - Item 5 (validation surface): the same declaration that
drives completion can drive parser-side validation —
ClosedValues::validatereturnstruefor 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
impl ClosedValues
Sourcepub fn into_provider(self) -> ValueProvider
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
impl Clone for ClosedValues
Source§fn clone(&self) -> ClosedValues
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ClosedValues
impl Debug for ClosedValues
Source§impl From<ClosedValues> for ValueProvider
Convenience: hand any ClosedValues to APIs that take a
ValueProvider without explicit .into_provider().
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
fn from(cv: ClosedValues) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for ClosedValues
impl RefUnwindSafe for ClosedValues
impl Send for ClosedValues
impl Sync for ClosedValues
impl Unpin for ClosedValues
impl UnsafeUnpin for ClosedValues
impl UnwindSafe for ClosedValues
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
Mutably borrows from an owned value. Read more