pub struct FwdPolicy<Set, Ser, Chk> { /* private fields */ }
Expand description
FwdPolicy
matching the command line arguments with Opt
in the Set
.
The option would match failed if any special Error
raised during option processing.
FwdPolicy
will return Some(ReturnVal
) if match successful.
FwdPolicy
process the option before any
NOA(Cmd
, Pos
and Main
).
During parsing, you can get the value of any option in the handler of NOA.
§Examples
let mut policy = AFwdPolicy::default();
let mut set = policy.default_set();
let mut inv = policy.default_inv();
let mut ser = policy.default_ser();
let filter_id = set.add_opt("--/filter=b")?.run()?;
let pos_id = set.add_opt("pos=p@*")?
.set_pos_type::<String>()
.set_values(vec![])
.run()?;
inv.entry(pos_id).on(
move |set: &mut ASet,
_: &mut ASer,
filter: ser::Value<Vec<&str>>,
mut value: ctx::Value<String>| {
let not_filter = set[filter_id].val::<bool>()?;
let valid = if !*not_filter {
!filter.iter().any(|&v| v == value.as_str())
} else {
true
};
Ok(valid.then(|| value.take()))
},
);
let args = Args::from(["app", "set", "42", "foo", "bar"]);
for opt in set.iter_mut() {
opt.init()?;
}
ser.sve_insert(ser::Value::new(vec!["foo", "bar"]));
policy.parse(&mut set, &mut inv, &mut ser, ARef::new(args))?;
let values = set[pos_id].vals::<String>()?;
assert_eq!(values[0], "set");
assert_eq!(values[1], "42");
let args = Args::from(["app", "--/filter", "set", "42", "foo", "bar"]);
for opt in set.iter_mut() {
opt.init()?;
}
policy.parse(&mut set, &mut inv, &mut ser, ARef::new(args))?;
let values = set[pos_id].vals::<String>()?;
assert_eq!(values[0], "set");
assert_eq!(values[1], "42");
assert_eq!(values[2], "foo");
assert_eq!(values[3], "bar");
Implementations§
source§impl<Set, Ser, Chk> FwdPolicy<Set, Ser, Chk>where
Chk: Default,
impl<Set, Ser, Chk> FwdPolicy<Set, Ser, Chk>where
Chk: Default,
pub fn new(strict: bool, style: OptStyleManager) -> Self
source§impl<Set, Ser, Chk> FwdPolicy<Set, Ser, Chk>
impl<Set, Ser, Chk> FwdPolicy<Set, Ser, Chk>
sourcepub fn with_strict(self, strict: bool) -> Self
pub fn with_strict(self, strict: bool) -> Self
In strict mode, if an argument looks like an option (it matched any option prefix), then it must matched.
pub fn with_styles(self, styles: Vec<UserStyle>) -> Self
pub fn with_checker(self, checker: Chk) -> Self
pub fn with_overload(self, overload: bool) -> Self
pub fn set_checker(&mut self, checker: Chk) -> &mut Self
pub fn checker(&self) -> &Chk
pub fn checker_mut(&mut self) -> &mut Chk
Trait Implementations§
source§impl<Set, Ser, Chk> APolicyExt<FwdPolicy<Set, Ser, Chk>> for FwdPolicy<Set, Ser, Chk>
impl<Set, Ser, Chk> APolicyExt<FwdPolicy<Set, Ser, Chk>> for FwdPolicy<Set, Ser, Chk>
fn default_set(&self) -> Set
fn default_ser(&self) -> Ser
fn default_inv<'a>(&self) -> <FwdPolicy<Set, Ser, Chk> as Policy>::Inv<'a>
source§impl<Set, Ser, Chk> PolicySettings for FwdPolicy<Set, Ser, Chk>
impl<Set, Ser, Chk> PolicySettings for FwdPolicy<Set, Ser, Chk>
fn style_manager(&self) -> &OptStyleManager
fn style_manager_mut(&mut self) -> &mut OptStyleManager
fn strict(&self) -> bool
fn styles(&self) -> &[UserStyle]
fn no_delay(&self) -> Option<&[AStr]>
fn overload(&self) -> bool
fn set_strict(&mut self, strict: bool) -> &mut Self
fn set_styles(&mut self, styles: Vec<UserStyle>) -> &mut Self
fn set_no_delay(&mut self, _: impl Into<AStr>) -> &mut Self
fn set_overload(&mut self, overload: bool) -> &mut Self
Auto Trait Implementations§
impl<Set, Ser, Chk> Freeze for FwdPolicy<Set, Ser, Chk>where
Chk: Freeze,
impl<Set, Ser, Chk> RefUnwindSafe for FwdPolicy<Set, Ser, Chk>
impl<Set, Ser, Chk> Send for FwdPolicy<Set, Ser, Chk>
impl<Set, Ser, Chk> Sync for FwdPolicy<Set, Ser, Chk>
impl<Set, Ser, Chk> Unpin for FwdPolicy<Set, Ser, Chk>
impl<Set, Ser, Chk> UnwindSafe for FwdPolicy<Set, Ser, Chk>
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