Struct ArgSpecBuilder

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

Builder type for ArgSpec.

Implementations§

Source§

impl ArgSpecBuilder

Source

pub fn done(self) -> Result<ArgSpec>

Completes building the ArgSpec. Returns [Ok(ArgSpec)] if no build errors and [Err(Error)] if otherwise.

§Example
use easy_args::ArgSpec;

let spec = ArgSpec::build()
    .uinteger("chickens")
    .done().
    unwrap();
Source

pub fn parse(self) -> Result<Args>

Little Wrapper function that will complete building the ArgSpec and immediately call [parse()].

§Example
use easy_args::arg_spec;

let args = arg_spec! {
    fullscreen: bool,
    vsync: bool,
    username: String
}
.parse()
.unwrap();
Source

pub fn arg(self, name: impl Into<String>, ty: ArgType) -> ArgSpecBuilder

Adds an argument the the ArgSpec with a given name and type.

§Example
use easy_args::{ArgSpec, ArgType};

let spec = ArgSpec::build()
    .arg("flag", ArgType::Boolean)
    .done()
    .unwrap();
Source

pub fn boolean(self, name: impl Into<String>) -> ArgSpecBuilder

Adds a boolean argument to the ArgSpec.

§Example
use easy_args::{ArgSpec, ArgType};

 let spec = ArgSpec::build()
    .boolean("vsync")
    .done()
    .unwrap();
 assert_eq!(spec.has_arg("vsync", ArgType::Boolean), true);
Source

pub fn integer(self, name: impl Into<String>) -> ArgSpecBuilder

Adds an i64 argument to the ArgSpec.

§Exmaple
use easy_args::{ArgSpec, ArgType};

let spec = ArgSpec::build()
    .integer("num-bananas")
    .done()
    .unwrap();
assert_eq!(spec.has_arg("num-bananas", ArgType::Integer), true);
Source

pub fn uinteger(self, name: impl Into<String>) -> ArgSpecBuilder

Adds a u64 argument to the ArgSpec.

§Exmaple
use easy_args::{ArgSpec, ArgType};

let spec = ArgSpec::build()
    .uinteger("screen-width")
    .done()
    .unwrap();
assert_eq!(spec.has_arg("screen-width", ArgType::UInteger), true);
Source

pub fn float(self, name: impl Into<String>) -> ArgSpecBuilder

Adds an f64 argument to the ArgSpec.

§Exmaple
use easy_args::{ArgSpec, ArgType};

let spec = ArgSpec::build()
    .float("gravity")
    .done()
    .unwrap();
assert_eq!(spec.has_arg("gravity", ArgType::Float), true);
Source

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

Adds a String argument to the ArgSpec.

§Exmaple
use easy_args::{ArgSpec, ArgType};

let spec = ArgSpec::build()
    .string("MOTD")
    .done()
    .unwrap();
assert_eq!(spec.has_arg("MOTD", ArgType::String), true);
Source

pub fn boolean_array( self, size: usize, name: impl Into<String>, ) -> ArgSpecBuilder

Adds a boolean array argument to the ArgSpec.

§Example
use easy_args::{ArgSpec, ArgType};

 let spec = ArgSpec::build()
    .boolean_array(2, "bools")
    .done()
    .unwrap();
 assert_eq!(spec.has_arg("bools", ArgType::BooleanArray(2)), true);
Source

pub fn integer_array( self, size: usize, name: impl Into<String>, ) -> ArgSpecBuilder

Adds an i64 array argument to the ArgSpec.

§Exmaple
use easy_args::{ArgSpec, ArgType};

let spec = ArgSpec::build()
    .integer_array(3, "position")
    .done()
    .unwrap();
assert_eq!(spec.has_arg("position", ArgType::IntegerArray(3)), true);
Source

pub fn uinteger_array( self, size: usize, name: impl Into<String>, ) -> ArgSpecBuilder

Adds a u64 array argument to the ArgSpec.

§Exmaple
use easy_args::{ArgSpec, ArgType};

let spec = ArgSpec::build()
    .uinteger_array(2, "size")
    .done()
    .unwrap();
assert_eq!(spec.has_arg("size", ArgType::UIntegerArray(2)), true);
Source

pub fn float_array(self, size: usize, name: impl Into<String>) -> ArgSpecBuilder

Adds a f64 array argument to the ArgSpec.

§Exmaple
use easy_args::{ArgSpec, ArgType};

let spec = ArgSpec::build()
    .float_array(3, "position")
    .done()
    .unwrap();
assert_eq!(spec.has_arg("position", ArgType::FloatArray(2)), true);
Source

pub fn string_array( self, size: usize, name: impl Into<String>, ) -> ArgSpecBuilder

Adds a String array argument to the ArgSpec.

§Exmaple
use easy_args::{ArgSpec, ArgType};

let spec = ArgSpec::build()
    .string_array(2, "name")
    .done()
    .unwrap();
assert_eq!(spec.has_arg("name", ArgType::StringArray(2)), true);

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.