Struct Args

Source
pub struct Args { /* private fields */ }
Expand description

Holds all the command-line arguments given by the user.

Each argument is contained within a HashMap that can be index by the argument’s name.

Implementations§

Source§

impl Args

Source

pub fn is_set(&self, name: impl Into<String>) -> bool

Determines if an argument of a given name was set by the user in the command-line.

§Example
use easy_args::arg_spec;

let args = arg_spec!(size: [u64; 2]).parse().unwrap();
if args.is_set("size") {
    // resize the window height
}
Source

pub fn boolean(&self, name: impl Into<String>) -> Option<&bool>

Returns a reference to the boolean value that corresponds with the given argument name.

§Example
use easy_args::arg_spec;

let args = arg_spec!(fullscreen: bool).parse().unwrap();
if args.boolean("fullscreen") == Some(&true) {
    // go fullscreen
}
Source

pub fn integer(&self, name: impl Into<String>) -> Option<&i64>

Returns a reference to the i64 value that corresponds with the given argument name.

§Example
use easy_args::arg_spec;

let args = arg_spec!(leaves: i64).parse().unwrap();
let num_leaves_in_pile = *args.integer("leaves").unwrap_or(&0);
Source

pub fn uinteger(&self, name: impl Into<String>) -> Option<&u64>

Returns a reference to the u64 value that corresponds with the given argument name.

§Example
use easy_args::arg_spec;

let args = arg_spec!(size: u64).parse().unwrap();
let size = *args.uinteger("size").unwrap_or(&0);
Source

pub fn float(&self, name: impl Into<String>) -> Option<&f64>

Returns a reference to the f64 value that corresponds with the given argument name.

§Example
use easy_args::arg_spec;

let args = arg_spec!(gravity: f64).parse().unwrap();
let size = *args.float("gravity").unwrap_or(&9.81);
Source

pub fn string(&self, name: impl Into<String>) -> Option<&String>

Returns a reference to the String value that corresponds with the given argument name.

§Exmaple
use easy_args::arg_spec;

let args = arg_spec!(username: String).parse().unwrap();
let username = args.string("username").unwrap_or(&"Guest".to_string());
Source

pub fn boolean_array(&self, name: impl Into<String>) -> Option<&[bool]>

Returns a reference to the boolean slice that corresponds with the given argument name.

§Example
use easy_args::arg_spec;

let args = arg_spec!(flags: [bool; 5]).parse().unwrap();
if let Some(flags) = args.boolean_array("flags") {
    // do something with flags
}
Source

pub fn integer_array(&self, name: impl Into<String>) -> Option<&[i64]>

Returns a reference to the i64 slice that corresponds with the given argument name.

§Example
use easy_args::arg_spec;

let args = arg_spec!(position: [i64; 3]).parse().unwrap();
if let Some([x, y, z]) = args.integer_array("position") {
    // do something with the position
}
Source

pub fn uinteger_array(&self, name: impl Into<String>) -> Option<&[u64]>

Returns a reference to the u64 slice that corresponds with the given argument name.

§Example
use easy_args::arg_spec;

let args = arg_spec!(size: [u64; 2]).parse().unwrap();
if let Some([width, height]) = args.uinteger_array("size") {
    // do something with screen size
}
Source

pub fn float_array(&self, name: impl Into<String>) -> Option<&[f64]>

Returns a reference to the f64 slice that corresponds with the given argument name.

§Example
use easy_args::arg_spec;

let args = arg_spec!(position: [f64; 3]).parse().unwrap();
if let Some([x, y, z]) = args.float_array("position") {
    // do something with position
}
Source

pub fn string_array(&self, name: impl Into<String>) -> Option<&[String]>

Returns a reference to the String slice that corresponds with the given argument name.

§Exmaple
use easy_args::arg_spec;

let args = arg_spec!(login_details: [String; 2]).parse().unwrap();
if let Some([username, password]) = args.string_array("login_details") {
    // do something with username and password
}
Source

pub fn free_args(&self) -> &Vec<String>

A Vector of all strings passed as command-line arguments that weren’t arguments of the ArgSpec.

§Example
use easy_args::arg_spec;

let args = arg_spec!().parse().unwrap();
for arg in args.free_args() {
    println!("What the heck is this? '{}'.", arg);
}

Trait Implementations§

Source§

impl Debug for Args

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Args

§

impl RefUnwindSafe for Args

§

impl Send for Args

§

impl Sync for Args

§

impl Unpin for Args

§

impl UnwindSafe for Args

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.