Opt

Struct Opt 

Source
pub struct Opt { /* private fields */ }

Implementations§

Source§

impl Opt

Source

pub fn new( long_name: Option<String>, short_name: Option<char>, has_arg: HasArg, desc: &str, ) -> Result<Self, NulError>

Examples found in repository?
examples/ex1/main.rs (line 9)
7fn main() -> OptResult<()> {
8    let longopts = &[
9        Opt::new(None, Some('v'), HasArg::NoArgument, "show version.").unwrap(),
10        Opt::new(None, Some('h'), HasArg::NoArgument, "help information.").unwrap(),
11        Opt::new(None, Some('a'), HasArg::RequiredArgument, "add record to table.").unwrap(),
12        Opt::new(None, Some('r'), HasArg::OptionalArgument, "remove record from table.").unwrap(),
13        Opt::new(None, Some('m'), HasArg::NoArgument, "modify the record in table.").unwrap(),
14        Opt::new(None, Some('q'), HasArg::NoArgument, "query the table.").unwrap(),
15    ];
16
17    usage("ex1", "this is ex1 example.", env!("CARGO_PKG_VERSION"), longopts);
18    let p = getopt_long(longopts)?;
19    println!("{}", p);
20    Ok(())
21}
More examples
Hide additional examples
examples/ex2/main.rs (line 9)
7fn main() -> OptResult<()> {
8    let longopts = &[
9        Opt::new(None, Some('v'), HasArg::NoArgument, "show version.").unwrap(),
10        Opt::new(None, Some('h'), HasArg::NoArgument, "help information.").unwrap(),
11        Opt::new(Some("add".to_owned()), Some('a'), HasArg::RequiredArgument, "add record to table.").unwrap(),
12        Opt::new(Some("remove".to_owned()), Some('r'), HasArg::OptionalArgument, "remove record from table.").unwrap(),
13        Opt::new(Some("modify".to_owned()), Some('m'), HasArg::NoArgument, "modify the record in table.").unwrap(),
14        Opt::new(Some("query".to_owned()), None, HasArg::NoArgument, "query the table.").unwrap(),
15    ];
16
17    usage("ex2", "this is ex2 example.", env!("CARGO_PKG_VERSION"), longopts);
18    match getopt_long(longopts) {
19        Ok(p) => println!("Arguments:\n{}", p),
20        Err(e) => println!("{}", e),
21    }
22    
23    Ok(())
24}

Trait Implementations§

Source§

impl Display for Opt

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Opt

§

impl RefUnwindSafe for Opt

§

impl Send for Opt

§

impl Sync for Opt

§

impl Unpin for Opt

§

impl UnwindSafe for Opt

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.