Skip to main content

StrictNode

Struct StrictNode 

Source
pub struct StrictNode<const HAS_CATEGORY: bool, const HAS_LEVEL: bool> { /* private fields */ }
Expand description

Type-state wrapper around Node that tracks at the type level whether the node has been given a category and an explicit tap-tier level.

Used together with CommandTree::strict_command / CommandTree::strict_group to force compile-time enforcement of the stratified completion contract: an app that opts into strict mode cannot register an uncategorized or unleveled command, because the registration call itself will not type-check unless both fields have been provided.

The two bool const generics flip from false to true when the matching builder method is called:

  • with_category("…")HAS_CATEGORY = true
  • with_level(N)HAS_LEVEL = true

Apps that don’t want the compile-time check can keep using the regular Node API and call CommandTree::require_metadata to get an equivalent runtime check at registration time.

§Successful registration (compiles)

use veks_completion::{CommandTree, StrictNode};
let tree = CommandTree::new("myapp")
    .strict_command(
        "run",
        StrictNode::leaf(&["--cycles=", "--threads="])
            .with_category("workloads")
            .with_level(1),
    );

§Missing category (compile error)

use veks_completion::{CommandTree, StrictNode};
let _tree = CommandTree::new("myapp").strict_command(
    "bad",
    StrictNode::leaf(&[]).with_level(1),  // missing with_category
);

§Missing level (compile error)

use veks_completion::{CommandTree, StrictNode};
let _tree = CommandTree::new("myapp").strict_command(
    "bad",
    StrictNode::leaf(&[]).with_category("x"),  // missing with_level
);

Implementations§

Source§

impl StrictNode<false, false>

Source

pub fn leaf(options: &[&str]) -> Self

Begin building a strict leaf node. Both with_category and with_level must be called before this can be passed to CommandTree::strict_command.

Source

pub fn leaf_with_flags(options: &[&str], flags: &[&str]) -> Self

Same as Node::leaf_with_flags but type-state-checked.

Source

pub fn group(children: Vec<(&str, Node)>) -> Self

Begin building a strict group node.

Source

pub fn from_node(node: Node) -> Self

Begin from an already-constructed Node. Useful when migrating an existing tree to strict mode incrementally.

Source§

impl<const C: bool, const L: bool> StrictNode<C, L>

Source

pub fn with_category(self, cat: &str) -> StrictNode<true, L>

Tag with a category. Flips HAS_CATEGORY to true.

Source

pub fn with_level(self, lvl: u32) -> StrictNode<C, true>

Set the tap-tier level. Flips HAS_LEVEL to true.

Source

pub fn with_value_provider(self, option: &str, provider: ValueProvider) -> Self

Forward through to the inner node’s value-provider builder.

Source

pub fn with_dynamic_options(self, provider: DynamicOptionsProvider) -> Self

Forward through to the inner node’s dynamic-options builder.

Source§

impl StrictNode<true, true>

Source

pub fn into_node(self) -> Node

Unwrap a fully-qualified strict node into a plain Node. The compile-time guarantee carries through to the moment of unwrapping: only nodes that have set both category and level can be downgraded.

Auto Trait Implementations§

§

impl<const HAS_CATEGORY: bool, const HAS_LEVEL: bool> !RefUnwindSafe for StrictNode<HAS_CATEGORY, HAS_LEVEL>

§

impl<const HAS_CATEGORY: bool, const HAS_LEVEL: bool> !UnwindSafe for StrictNode<HAS_CATEGORY, HAS_LEVEL>

§

impl<const HAS_CATEGORY: bool, const HAS_LEVEL: bool> Freeze for StrictNode<HAS_CATEGORY, HAS_LEVEL>

§

impl<const HAS_CATEGORY: bool, const HAS_LEVEL: bool> Send for StrictNode<HAS_CATEGORY, HAS_LEVEL>

§

impl<const HAS_CATEGORY: bool, const HAS_LEVEL: bool> Sync for StrictNode<HAS_CATEGORY, HAS_LEVEL>

§

impl<const HAS_CATEGORY: bool, const HAS_LEVEL: bool> Unpin for StrictNode<HAS_CATEGORY, HAS_LEVEL>

§

impl<const HAS_CATEGORY: bool, const HAS_LEVEL: bool> UnsafeUnpin for StrictNode<HAS_CATEGORY, HAS_LEVEL>

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> 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, 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.