Struct getopt

Source
pub struct getopt {
    pub options: HashMap<char, String>,
    pub arguments: Vec<String>,
    pub option_has_arg: HashMap<char, bool>,
}
Expand description

Parsed command line options.

Created by new function. Structure contains isolated command line arguments and collected options with their optional values.

Structure can contain options which are not listed in optstring passed to new function. For strict parse mode pass this structure to validate function.

Fields§

§options: HashMap<char, String>

Map of command line options and their optional values extracted from command line arguments.

If an option does not have a value, an empty string “” is stored.

§arguments: Vec<String>

Isolated command line arguments without options.

§option_has_arg: HashMap<char, bool>

Map indicating whether an option has a required argument.

This map contains all recognized options. Inclusion of an option in this map does not mean that the option must always be present or supplied as a command line argument.

Implementations§

Source§

impl getopt

Source

pub fn len(&self) -> usize

Return number of command line arguments.

Its convience shortcut for getopt.arguments.len()

§Example
use std::env::args;
use getopt3::hideBin;

let getopt_rc = getopt3::new(hideBin(args()), "ab:c");
if let Ok(g) = getopt_rc {
   println!("Number of command line arguments is {}", g.len());
};
Source

pub fn iter(&self) -> Iter<'_, String>

Returns Iterator over command line arguments.

§Example
use std::env::args;
use getopt3::hideBin;

let getopt_rc = getopt3::new(hideBin(args()), "abc");
if let Ok(my_getopt) = getopt_rc {
   for arg in my_getopt.iter() {
      println!("Argument: {}", arg);
   }
}
Source

pub fn get(&self, option: char) -> Option<&String>

Return command line option value.

Its convience shortcut for getopt.options.get()

§Return value
  1. If option were supplied on command line returned value is Some.
  2. If option doesn’t have argument or argument is missing, reference to empty String is returned.
  3. If option were not supplied by user returned value is None.
§Example
use std::env::args;
use getopt3::hideBin;

let getopt_rc = getopt3::new(hideBin(args()), "ab:c");
if let Ok(my_getopt) = getopt_rc {
   if let Some(b_value) = my_getopt.get('b') {
      println!("-b argument is: {}", b_value);
   }
}

Trait Implementations§

Source§

impl<'a> IntoIterator for &'a getopt

Source§

type Item = &'a String

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, String>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for getopt

Source§

type Item = String

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<String>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl Freeze for getopt

§

impl RefUnwindSafe for getopt

§

impl Send for getopt

§

impl Sync for getopt

§

impl Unpin for getopt

§

impl UnwindSafe for getopt

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.