Struct Args

Source
pub struct Args<'a>(/* private fields */);
Expand description

Stores an IndexMap of Args. See examples.

Implementations§

Source§

impl<'a> Args<'a>

Source

pub fn new() -> Self

A convenience function for making a new empty Args(). In truth, it just calls default()

Source

pub fn with_capacity(capacity: usize) -> Self

Initializes internal hashmap with a given capacity, to reduce required memory allocations. Potentially useful if you’re planning to call .push() a lot.

Source

pub fn poke<T>(&mut self, name: &'a str) -> Result<&T, DynArgError<'_>>
where T: 'static,

Like get(), but marks the value as used. Because it changes self, it requires mutable access to self. This, of course, may make it unusable for some use cases.

Source

pub fn get<T>(&self, name: &'a str) -> Result<&T, DynArgError<'_>>
where T: 'static,

Retrieve a value by name. It’s recommended to explicitly specify type via generics, e.g.:

use dynarg::Args;
let mut args = Args::default();
args.insert_i32("meaning_of_life", 42);
let arg = args.get::<i32>("meaning_of_life");
Source

pub fn insert(&mut self, name: &'a str, value: Box<dyn Any>)

Inserts a value with a dynamic type. Value must be wrapped in a Box<> pointer. BTW, when will the box keyword syntax be stable? That would make a lot of code more elegant.

Source

pub fn all_used(&self) -> bool

Returns true if every argument is marked as “used”. Returns false otherwise.

Source

pub fn iter_not_used_name(&self) -> impl Iterator<Item = &str>

Returns a iterator of arguments marked as not used.

Source

pub fn iter_used_name(&self) -> impl Iterator<Item = &str>

Returns an iterator of arguments marked as used.

Source

pub fn reset_used_status(&mut self)

Resets the used status of every argument in the IndexMap.

Source

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

Source

pub fn insert_string(&mut self, name: &'a str, value: String)

Dynamically generated inserter

Source

pub fn get_string(&mut self, name: &'a str) -> Result<&String, DynArgError<'_>>

Dynamically generated getter

Source

pub fn poke_string(&mut self, name: &'a str) -> Result<&String, DynArgError<'_>>

Dynamically generated poker

Source

pub fn insert_f32(&mut self, name: &'a str, value: f32)

Dynamically generated inserter

Source

pub fn get_f32(&mut self, name: &'a str) -> Result<&f32, DynArgError<'_>>

Dynamically generated getter

Source

pub fn poke_f32(&mut self, name: &'a str) -> Result<&f32, DynArgError<'_>>

Dynamically generated poker

Source

pub fn insert_f64(&mut self, name: &'a str, value: f64)

Dynamically generated inserter

Source

pub fn get_f64(&mut self, name: &'a str) -> Result<&f64, DynArgError<'_>>

Dynamically generated getter

Source

pub fn poke_f64(&mut self, name: &'a str) -> Result<&f64, DynArgError<'_>>

Dynamically generated poker

Source

pub fn insert_i32(&mut self, name: &'a str, value: i32)

Dynamically generated inserter

Source

pub fn get_i32(&mut self, name: &'a str) -> Result<&i32, DynArgError<'_>>

Dynamically generated getter

Source

pub fn poke_i32(&mut self, name: &'a str) -> Result<&i32, DynArgError<'_>>

Dynamically generated poker

Source

pub fn insert_i64(&mut self, name: &'a str, value: i64)

Dynamically generated inserter

Source

pub fn get_i64(&mut self, name: &'a str) -> Result<&i64, DynArgError<'_>>

Dynamically generated getter

Source

pub fn poke_i64(&mut self, name: &'a str) -> Result<&i64, DynArgError<'_>>

Dynamically generated poker

Source

pub fn insert_bool(&mut self, name: &'a str, value: bool)

Dynamically generated inserter

Source

pub fn get_bool(&mut self, name: &'a str) -> Result<&bool, DynArgError<'_>>

Dynamically generated getter

Source

pub fn poke_bool(&mut self, name: &'a str) -> Result<&bool, DynArgError<'_>>

Dynamically generated poker

Trait Implementations§

Source§

impl<'a> Default for Args<'a>

Source§

fn default() -> Args<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Args<'a>

§

impl<'a> !RefUnwindSafe for Args<'a>

§

impl<'a> !Send for Args<'a>

§

impl<'a> !Sync for Args<'a>

§

impl<'a> Unpin for Args<'a>

§

impl<'a> !UnwindSafe for Args<'a>

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.