pub struct Flag<T> { /* private fields */ }
Expand description
The state associated with a single flag.
An invocation of gflags::define!
with flag long name --the_name
and
flag type T
declares an item static the_name: Flag<T>
through which the
state of the flag can be accessed.
After gflags::parse()
has been called, the value of a flag is available
through its .FLAG
field which is of type T
.
Examples
use std::path::Path;
gflags::define! {
/// Search for patterns from the given file, with one pattern per line.
-f, --file: &Path
}
fn main() {
let patterns = gflags::parse();
if file.is_present() {
let path = file.FLAG;
println!("searching for patterns from file: {}", path.display());
} else {
println!("searching for patterns given on command line: {:?}", patterns);
}
}
Implementations
sourceimpl<T: 'static> Flag<T>
impl<T: 'static> Flag<T>
sourcepub fn is_present(&self) -> bool
pub fn is_present(&self) -> bool
Whether this flag was provided on the command line.
When using flags for which a default value is not provided, be sure to
check .is_present()
because accessing .FLAG
when not present will
cause a panic.
When a flag has a default value and is not passed on the command line,
is_present()
will be false and .FLAG
will refer to the default
value.
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Flag<T>
impl<T> Send for Flag<T>
impl<T> Sync for Flag<T>
impl<T> Unpin for Flag<T>
impl<T> UnwindSafe for Flag<T>where
T: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more