Struct Parser

Source
pub struct Parser {
    pub flag_pattern: char,
    pub long_flag_prefix: String,
    pub eq: char,
}
Expand description

Struct of information for parse

Fields§

§flag_pattern: char

flag_pattern. Default is ‘-’.

§long_flag_prefix: String

Long-flag pre&&fix. Default is “–”.

§eq: char

equal symbol. Default is “=”

Implementations§

Source§

impl Parser

Source

pub fn new(flag_pattern: char, long_flag_prefix: &str) -> Parser

Creates a new Parser with flag_pattern and long_flag_prefix.

Source

pub fn long_flag(&self, str: &str) -> bool

Returns true if str has long-flag prefix (default prefix: –). ロングフラグか判定する

Source

pub fn flag(&self, str: &str) -> bool

Returns true if str has flag prefix (default prefix: -). フラグならtrueを返す

Source

pub fn with_all_field( flag_pattern: char, long_flag_prefix: String, eq: char, ) -> Parser

Builds a new Parser with all options

Source

pub fn remove_long_flag_prefix(&self, arg: String) -> String

Removes long-flag prefix from arg.

Source

pub fn get_short_flag_name(&self, arg: String) -> String

Gets short flag name.

Source

pub fn middle_parse( &self, args: VecDeque<String>, inter_mediate_args: VecDeque<MiddleArg>, last: MiddleArg, ) -> (Option<String>, VecDeque<String>, VecDeque<MiddleArg>, MiddleArg)

Parses args and convert into MiddileArgs

Source

pub fn long_middle(&self, long_flag: String) -> MiddleArg

Converts long_flag to MiddleArg::LongFlag.

Source

pub fn short_middle(&self, short_flag: String) -> MiddleArg

Converts short_flag to MiddleArg::ShortFlag.

Source

pub fn parse_inter_mediate_args<T: FlagSearch, S: FlagSearch>( &self, local_flags: &T, current_common_flags: &S, c: Context, flag_only: bool, ) -> (Context, Option<VecDeque<String>>)

Parses c’s parsing_args (call inter mediate args in parsing).

Source

pub fn parse_middle_long_flag<T: FlagSearch, S: FlagSearch>( &self, name_or_alias: String, val: FlagValue, local_flags: &T, current_common_flags: &S, c: &Context, l_flags: VecDeque<(String, FlagValue)>, c_flags: VecDeque<(String, FlagValue)>, e_list: VecDeque<ErrorInfo>, ) -> (VecDeque<(String, FlagValue)>, VecDeque<(String, FlagValue)>, VecDeque<ErrorInfo>)

Parses middle long flag.

Source

pub fn parse_middle_short_flag<T: FlagSearch, S: FlagSearch>( &self, short_alias: String, flag_val: FlagValue, local_flags: &T, current_common_flags: &S, c: &Context, l_flags: VecDeque<(String, FlagValue)>, c_flags: VecDeque<(String, FlagValue)>, e_list: VecDeque<ErrorInfo>, ) -> (VecDeque<(String, FlagValue)>, VecDeque<(String, FlagValue)>, VecDeque<ErrorInfo>)

Parse middle short flag

Source

pub fn parse_middle_normal_arg<T: FlagSearch, S: FlagSearch>( &self, inter_mediate_args: VecDeque<MiddleArg>, normal_arg: String, local_flags: &T, current_common_flags: &S, c: Context, non_flag_args: VecDeque<String>, l_flags: VecDeque<(String, FlagValue)>, c_flags: VecDeque<(String, FlagValue)>, e_list: VecDeque<ErrorInfo>, flag_only: bool, ) -> (Context, VecDeque<MiddleArg>, VecDeque<String>, VecDeque<(String, FlagValue)>, VecDeque<(String, FlagValue)>, VecDeque<ErrorInfo>)

Parse middle normal arg

Source

pub fn parse_next_if_middle_arg<T: FlagSearch, S: FlagSearch>( &self, inter_mediate_args: VecDeque<MiddleArg>, non_flag_args: VecDeque<String>, local_flags: &T, current_common_flags: &S, c: Context, l_flags: VecDeque<(String, FlagValue)>, c_flags: VecDeque<(String, FlagValue)>, e_list: VecDeque<ErrorInfo>, flag_only: bool, ) -> (Context, VecDeque<MiddleArg>, VecDeque<String>, VecDeque<(String, FlagValue)>, VecDeque<(String, FlagValue)>, VecDeque<ErrorInfo>)

Parses args if next middle args exist.

Source

pub fn parse_args_until_end<T: FlagSearch, S: FlagSearch>( self, local_flags: &T, current_common_flags: &S, c: Context, ) -> Context

Parse args until args’ end.

Source

pub fn parse_flags_start_with_long_flag<T: FlagSearch, S: FlagSearch>( &self, long_flag: String, local_flags: &T, current_common_flags: &S, c: Context, ) -> (Option<String>, Context)

Parses flags start with long flag until non-flag arg appeared.

Source

pub fn parse_flags_start_with_short_flag<T: FlagSearch, S: FlagSearch>( &self, short_flag: String, local_flags: &T, current_common_flags: &S, c: Context, ) -> (Option<String>, Context)

Parses flags start with short flag until args appeared.

Source

pub fn parse_next_if_flag<T: FlagSearch, S: FlagSearch>( &self, local_flags: &T, current_common_flags: &S, c: Context, ) -> (Option<String>, Context)

Parses(or assigns parse functions) args if next args.

Trait Implementations§

Source§

impl Default for Parser

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<(char, char)> for Parser

Source§

fn from((flag_pattern, eq): (char, char)) -> Self

Converts to this type from the input type.
Source§

impl From<char> for Parser

Source§

fn from(flag_pattern: char) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Parser

§

impl RefUnwindSafe for Parser

§

impl Send for Parser

§

impl Sync for Parser

§

impl Unpin for Parser

§

impl UnwindSafe for Parser

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, 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.