pub struct SubcommandMap { /* private fields */ }Expand description
Map of subcommand patterns to their entries. Patterns are space-separated
strings (e.g. "pr create") matched via longest_match.
Deserialization validates that every pattern key respects
MAX_SUBCOMMAND_DEPTH — patterns with more words are rejected at parse
time with a clear error naming the offending key. Nested SubcommandEntry
maps are validated recursively because SubcommandEntry::subcommands is
itself a SubcommandMap.
Implementations§
Source§impl SubcommandMap
impl SubcommandMap
pub fn new() -> Self
Sourcepub fn insert(&mut self, pattern: impl Into<String>, entry: SubcommandEntry)
pub fn insert(&mut self, pattern: impl Into<String>, entry: SubcommandEntry)
Insert a subcommand pattern and its entry.
§Panics (debug builds)
Debug-asserts that the pattern does not exceed MAX_SUBCOMMAND_DEPTH.
The deserialization path validates this invariant at parse time, so
patterns from TOML config are always safe. This assert catches mistakes
in programmatic construction during development.
pub fn get(&self, pattern: &str) -> Option<&SubcommandEntry>
pub fn is_empty(&self) -> bool
pub fn iter(&self) -> impl Iterator<Item = (&str, &SubcommandEntry)>
pub fn extend(&mut self, other: SubcommandMap)
pub fn remove(&mut self, pattern: &str)
pub fn len(&self) -> usize
pub fn longest_match( &self, words: &[&Word], ) -> Option<(&SubcommandEntry, usize)>
Trait Implementations§
Source§impl Clone for SubcommandMap
impl Clone for SubcommandMap
Source§fn clone(&self) -> SubcommandMap
fn clone(&self) -> SubcommandMap
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 SubcommandMap
impl Debug for SubcommandMap
Source§impl Default for SubcommandMap
impl Default for SubcommandMap
Source§fn default() -> SubcommandMap
fn default() -> SubcommandMap
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for SubcommandMap
impl<'de> Deserialize<'de> for SubcommandMap
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'a> IntoIterator for &'a SubcommandMap
impl<'a> IntoIterator for &'a SubcommandMap
Source§type Item = (&'a str, &'a SubcommandEntry)
type Item = (&'a str, &'a SubcommandEntry)
The type of the elements being iterated over.
Source§type IntoIter = Map<Iter<'a, String, SubcommandEntry>, fn((&'a String, &'a SubcommandEntry)) -> (&'a str, &'a SubcommandEntry)>
type IntoIter = Map<Iter<'a, String, SubcommandEntry>, fn((&'a String, &'a SubcommandEntry)) -> (&'a str, &'a SubcommandEntry)>
Which kind of iterator are we turning this into?
Auto Trait Implementations§
impl Freeze for SubcommandMap
impl RefUnwindSafe for SubcommandMap
impl Send for SubcommandMap
impl Sync for SubcommandMap
impl Unpin for SubcommandMap
impl UnsafeUnpin for SubcommandMap
impl UnwindSafe for SubcommandMap
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