Skip to main content

PassedFlags

Struct PassedFlags 

Source
pub struct PassedFlags {
    pub map: HashMap<String, String>,
}
Expand description

Resolved flags delivered to the app’s main entry handler.

Constructed by crate::App::run when no subcommand is present and a main entry point has been registered via crate::App::main. The inner map uses canonical flag names as keys; boolean flags have the value "true".

Fields§

§map: HashMap<String, String>

The raw resolved flag map. Prefer the accessor methods over direct access.

Implementations§

Source§

impl PassedFlags

Source

pub fn get_flag_value(&self, name: &str) -> Option<&String>

Returns the value of a flag by its canonical name, if present.

Boolean flags (those with no explicit value) return "true".

Source

pub fn contains_flag(&self, name: &str) -> bool

Returns true if the named flag was passed by the user.

Examples found in repository?
examples/taskr.rs (line 138)
136fn entry(flags: PassedFlags) {
137    // Demonstrates: app-level main entry point with PassedFlags
138    if flags.contains_flag("verbose") {
139        println!("taskr: verbose mode active.");
140    } else {
141        println!("taskr: a toy task manager. Try 'taskr --help'.");
142    }
143}
Source

pub fn iter(&self) -> impl Iterator<Item = (&String, &String)>

Iterates over all (name, value) pairs in the resolved flag map.

Auto Trait Implementations§

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.