pub struct Parser<'a, Config: 'a> { /* private fields */ }
Expand description
Parser struct containing the config, a map of arguments to functions, and a function that is called when an argument is not in the map.
§Example
#[derive(PartialEq, Debug, Default)]
struct Config {
foo: bool,
bar: bool,
}
let cfg = arg_fn::Parser::new(Config::default(), |_cfg, _arg| {})
.arg("-foo", |cfg| cfg.foo = true)
.arg("-nofoo", |cfg| cfg.foo = false)
.arg("-bar", |cfg| cfg.bar = true)
.arg("-nobar", |cfg| cfg.bar = false)
.parse(["-bar", "-nofoo", "-foo", "-nobar", "-foo"]);
assert_eq!(
cfg,
Config {
foo: true,
bar: false,
}
)
Implementations§
Source§impl<'a, Config: 'a> Parser<'a, Config>
impl<'a, Config: 'a> Parser<'a, Config>
pub fn new(config: Config, unknown: impl Fn(&mut Config, &'a str) + 'a) -> Self
pub fn with_arguments( config: Config, arguments: HashMap<Cow<'a, str>, Box<dyn Fn(&mut Config) + 'a>>, unknown: impl Fn(&mut Config, &'a str) + 'a, ) -> Self
pub fn arg( self, argument: impl Into<Cow<'a, str>>, callback: impl Fn(&mut Config) + 'a, ) -> Self
pub fn parse(self, input: impl IntoIterator<Item = &'a str>) -> Config
Trait Implementations§
Auto Trait Implementations§
impl<'a, Config> Freeze for Parser<'a, Config>where
Config: Freeze,
impl<'a, Config> !RefUnwindSafe for Parser<'a, Config>
impl<'a, Config> !Send for Parser<'a, Config>
impl<'a, Config> !Sync for Parser<'a, Config>
impl<'a, Config> Unpin for Parser<'a, Config>where
Config: Unpin,
impl<'a, Config> !UnwindSafe for Parser<'a, Config>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more