[−][src]Struct adante::Arguments
The meat of the library, describes an Argument
object and its methods
Fields
flags: Vec<Flag<F>>
A list of the user defined Flag types and optional values
actions: Vec<A>
A list of the user defined Action types
Implementations
impl<F: ArgumentType, A: ArgumentType> Arguments<F, A>
[src]
pub fn new() -> Self
[src]
A default constructor for the Arguments type.
Note: explicit type must be specified when using a default constructor, unlike vectors etc.
Examples
use adante::{Arguments, ArgumentType}; #[derive(Debug, Clone, Copy, PartialEq)] enum FlagType { Help, Verbose, Print, } impl ArgumentType for FlagType { fn from_str<ErrorType>(key: &str, error: ErrorType) -> Result<Self, ErrorType> { match key { "-h" | "--help" => Ok(Self::Help), "-v" | "--verbose" => Ok(Self::Verbose), "-p" | "--print" => Ok(Self::Print), _ => Err(error), } } } enum ActionType { Add, Remove, Edit, } impl ArgumentType for ActionType { fn from_str<ErrorType>(key: &str, error: ErrorType) -> Result<Self, ErrorType> { match key { "a" | "add" => Ok(Self::Add), "r" | "remove" => Ok(Self::Remove), "e" | "edit" => Ok(Self::Edit), _ => Err(error), } } } let blank_args: Arguments<FlagType, ActionType> = Arguments::new(); assert_eq!(blank_args.flags.len(), 0); assert_eq!(blank_args.actions.len(), 0);
pub fn parse<E: Error + Clone + Copy>(
env_args: Vec<&str>,
error: E
) -> Result<Arguments<F, A>, E>
[src]
env_args: Vec<&str>,
error: E
) -> Result<Arguments<F, A>, E>
The parsing function that returns a full Arguments object.
More complicated usages and tests can be found in the tests.rs file.
Examples
use adante::{ArgumentType, Error, Arguments}; #[derive(Debug, Clone, Copy)] enum ErrorType { Syntax, // EXTREMELY simple example // More complex examples are shown in // the documentation for Error } impl Error for ErrorType { fn handle(&self) { () } fn as_str(&self) -> &str { "Syntax Error" } } #[derive(Debug, Clone, Copy, PartialEq)] enum FlagType { Help, Verbose, Print, TestFail, // NOTE: For testing only // Use Error } impl ArgumentType for FlagType { fn from_str<ErrorType>(key: &str, error: ErrorType) -> Result<Self, ErrorType> { match key { "-h" | "--help" => Ok(Self::Help), "-v" | "--verbose" => Ok(Self::Verbose), "-p" | "--print" => Ok(Self::Print), _ => Err(error), } } } enum ActionType { Add, Remove, Edit, } impl ArgumentType for ActionType { fn from_str<ErrorType>(key: &str, error: ErrorType) -> Result<Self, ErrorType> { match key { "a" | "add" => Ok(Self::Add), "r" | "remove" => Ok(Self::Remove), "e" | "edit" => Ok(Self::Edit), _ => Err(error), } } } let env_args = vec!["-v"]; let env_args: Arguments<FlagType, ActionType> = match Arguments::parse(env_args, ErrorType::Syntax) { Ok(a) => a, Err(e) => Arguments::new() }; let mut result: FlagType = FlagType::TestFail; if env_args.flags.len() != 0 { result = env_args.flags[0].key; } assert_eq!(result, FlagType::Verbose);
Trait Implementations
impl<F: Debug + ArgumentType, A: Debug + ArgumentType> Debug for Arguments<F, A>
[src]
Auto Trait Implementations
impl<F, A> RefUnwindSafe for Arguments<F, A> where
A: RefUnwindSafe,
F: RefUnwindSafe,
[src]
A: RefUnwindSafe,
F: RefUnwindSafe,
impl<F, A> Send for Arguments<F, A> where
A: Send,
F: Send,
[src]
A: Send,
F: Send,
impl<F, A> Sync for Arguments<F, A> where
A: Sync,
F: Sync,
[src]
A: Sync,
F: Sync,
impl<F, A> Unpin for Arguments<F, A> where
A: Unpin,
F: Unpin,
[src]
A: Unpin,
F: Unpin,
impl<F, A> UnwindSafe for Arguments<F, A> where
A: UnwindSafe,
F: UnwindSafe,
[src]
A: UnwindSafe,
F: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,