Struct OptionList

Source
pub struct OptionList { /* private fields */ }
Expand description

Represents a collection of CommandOptions.

Implementations§

Source§

impl OptionList

Source

pub fn new() -> Self

Constructs a new empty Options.

Source

pub fn add(&mut self, option: CommandOption) -> Result<(), CommandOption>

Adds the specified CommandOption.

§Returns

false if there is an option with the same alias than the provided one.

Source

pub fn add_or_replace(&mut self, option: CommandOption)

Adds the specified CommandOption or replace it it already exists,

Source

pub fn get<S: AsRef<str>>(&self, name_or_alias: S) -> Option<&CommandOption>

Returns the CommandOption with the given name or alias or None if not found.

Source

pub fn get_by_name<S: AsRef<str>>(&self, name: S) -> Option<&CommandOption>

Returns the CommandOption with the given name or None if not found.

Source

pub fn get_by_alias<S: AsRef<str>>(&self, alias: S) -> Option<&CommandOption>

Returns the CommandOption with the given alias or None if not found.

Source

pub fn convert<T>(&self, option: &str) -> Result<T>
where T: FromStr + 'static, <T as FromStr>::Err: Display,

Converts the argument value of the given option to the type T or results Err if:

  • The option is not found.
  • The option takes no arguments.
  • The option takes more than 1 argument.
  • The argument value parse fail.
Source

pub fn convert_all<T>(&self, option: &str) -> Result<Vec<T>>
where T: FromStr + 'static, <T as FromStr>::Err: Display,

Converts all the argument values of the given option to the type T or results Err if:

  • The option is not found.
  • The option takes no arguments.
  • The option takes more than 1 argument.
  • The argument values parse fail.
Source

pub fn get_arg<S: AsRef<str>>(&self, option: S) -> Option<&Argument>

Returns the Argument of the option with the given name or alias or None if the option cannot be found or have more than 1 argument.

Source

pub fn get_args<S: AsRef<str>>(&self, option: S) -> Option<&ArgumentList>

Returns the ArgumentList of the option with the given name or alias, or None if the option canno tbe found.

Source

pub fn contains<S: AsRef<str>>(&self, option: S) -> bool

Returns true if there is an option with the given name or alias.

Source

pub fn len(&self) -> usize

Returns the number of options in this collection.

Source

pub fn is_empty(&self) -> bool

Returns true if there is no options.

Source

pub fn clear(&mut self)

Removes all the Options.

Source

pub fn iter(&self) -> Iter<'_>

Returns an ExactSizeIterator over the CommandOption of this collection.

Trait Implementations§

Source§

impl Clone for OptionList

Source§

fn clone(&self) -> OptionList

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OptionList

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for OptionList

Source§

fn default() -> OptionList

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

impl<'de> Deserialize<'de> for OptionList

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Self, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Index<&str> for OptionList

Source§

type Output = CommandOption

The returned type after indexing.
Source§

fn index(&self, index: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a OptionList

Source§

type Item = &'a CommandOption

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for OptionList

Source§

type Item = CommandOption

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for OptionList

Source§

fn eq(&self, other: &OptionList) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for OptionList

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for OptionList

Source§

impl StructuralPartialEq for OptionList

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,