Args

Trait Args 

Source
pub trait Args<T> {
    // Required methods
    fn has_help(&self) -> bool;
    fn all(&self) -> Vec<T>;
}
Expand description

Abstraction over command-line argument collections for help detection and access.

§Type Parameters

  • T The type of individual arguments, typically string-like (e.g., String, &str).

§Rationale

  • Enables polymorphic argument handling without coupling to specific collection types.
  • Centralizes help flag detection logic for consistency across binaries.
  • Supports both owned and borrowed argument slices for flexibility.

§Performance

  • has_help performs a linear scan; suitable for small argument lists (typical CLI usage).
  • all clones arguments; use borrowed types (T = &str) to avoid allocation overhead.

Required Methods§

Source

fn has_help(&self) -> bool

Checks if the help flag (--help) is present in the arguments.

§Rationale
  • Standardized help detection avoids ad-hoc string comparisons in binaries.
  • Case-sensitive matching aligns with common CLI conventions.
Source

fn all(&self) -> Vec<T>

Returns a copy of all arguments.

§Rationale
  • Provides uniform access to arguments regardless of underlying storage.
  • Cloning ensures caller ownership; consider T = &str for zero-copy variants.

Implementations on Foreign Types§

Source§

impl Args<String> for Arguments

Source§

fn has_help(&self) -> bool

Source§

fn all(&self) -> Vec<String>

Source§

impl<T: AsRef<str> + Clone> Args<T> for Vec<T>

Source§

fn has_help(&self) -> bool

Source§

fn all(&self) -> Self

Implementors§