[][src]Struct flood_tide::Lex

pub struct Lex<'a> { /* fields omitted */ }

Lexical analyzer

this is analyzing command line arguments, returning tokens.

Examples

#[cfg(not(feature = "long_only"))]
#[cfg(feature = "option_argument")]
{
    use flood_tide::{Arg, Lex, Opt, OptNum};
     
    #[rustfmt::skip]
    let args = ["-ab", "--barn", "--eat", "jum"];
     
    #[rustfmt::skip]
    #[repr(u8)]
    #[derive(Debug, PartialEq)]
    enum CmdOP { A = 1, Barn, Eat, };
    impl CmdOP { pub const fn to(self) -> OptNum { self as OptNum } }
      
    #[rustfmt::skip]
    const OPT_ARY: [Opt;3] = [
        Opt { sho: b'a', lon: "",     has: Arg::No,  num: CmdOP::A.to(), },
        Opt { sho: b'b', lon: "barn", has: Arg::No,  num: CmdOP::Barn.to(), },
        Opt { sho: 0u8,  lon: "eat",  has: Arg::Yes, num: CmdOP::Eat.to(), },
    ];
    #[rustfmt::skip]
    const OPT_ARY_SHO_IDX: [(u8,usize);2] = [(b'a',0),(b'b',1)];
    
    let lex = Lex::create_with(&OPT_ARY, &OPT_ARY_SHO_IDX);
    let tokens = match lex.tokens_from(&args) {
        Ok(t) => t,
        Err(e) => unreachable!(),
    };
}

Implementations

impl<'a> Lex<'a>[src]

pub fn create_with(
    opt_ary: &'a [Opt<'_>],
    sho_idx_ary: &'a [(u8, usize)]
) -> Lex<'a>
[src]

create lexical analyzer

pub fn subcmd(mut self: Self, subcmd_ary: &'a [&'a str]) -> Self[src]

setup subcommand ary

pub fn tokens_from(&'a self, args: &'a [&'a str]) -> Result<Tokens<'a>, OPErr>[src]

analyze and return tokens

Trait Implementations

impl<'a> Debug for Lex<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Lex<'a>[src]

impl<'a> Send for Lex<'a>[src]

impl<'a> Sync for Lex<'a>[src]

impl<'a> Unpin for Lex<'a>[src]

impl<'a> UnwindSafe for Lex<'a>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.