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 = truewith_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>
impl StrictNode<false, false>
Sourcepub fn leaf(options: &[&str]) -> Self
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.
Sourcepub fn leaf_with_flags(options: &[&str], flags: &[&str]) -> Self
pub fn leaf_with_flags(options: &[&str], flags: &[&str]) -> Self
Same as Node::leaf_with_flags but type-state-checked.
Source§impl<const C: bool, const L: bool> StrictNode<C, L>
impl<const C: bool, const L: bool> StrictNode<C, L>
Sourcepub fn with_category(self, cat: &str) -> StrictNode<true, L>
pub fn with_category(self, cat: &str) -> StrictNode<true, L>
Tag with a category. Flips HAS_CATEGORY to true.
Sourcepub fn with_level(self, lvl: u32) -> StrictNode<C, true>
pub fn with_level(self, lvl: u32) -> StrictNode<C, true>
Set the tap-tier level. Flips HAS_LEVEL to true.
Sourcepub fn with_value_provider(self, option: &str, provider: ValueProvider) -> Self
pub fn with_value_provider(self, option: &str, provider: ValueProvider) -> Self
Forward through to the inner node’s value-provider builder.
Sourcepub fn with_dynamic_options(self, provider: DynamicOptionsProvider) -> Self
pub fn with_dynamic_options(self, provider: DynamicOptionsProvider) -> Self
Forward through to the inner node’s dynamic-options builder.