Skip to main content

SpecGroup

Struct SpecGroup 

Source
#[non_exhaustive]
pub struct SpecGroup { pub name: String, pub members: Vec<String>, pub required: bool, pub multiple: bool, }
Expand description

A set of flags that relate to one another as a set.

Everything here could be written as pairwise conflicts — for three members, three declarations, and for six, fifteen — except for the part that cannot: “one of these is required” is a statement about the set, and no rule written on an individual flag says it.

The two properties are clap’s, and are read the same way:

  • multiple (default false) — whether more than one member may be given. The default is what makes a bare group mutual exclusion.
  • required (default false) — whether at least one member must be given.

So the default group is “at most one of these”, required alone is “exactly one of these”, and multiple with required is “at least one of these”.

Members use the same selectors as other relationships: --long or -s for a flag, and the bare argument name for a positional.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: String

What this group is called. Used in messages, and it is how a reader tells two groups apart when a command has several.

§members: Vec<String>

The arguments in the group, as selectors. Flags use dashed spellings; positionals use their bare names.

§required: bool

Whether at least one member has to be given.

§multiple: bool

Whether more than one member may be given.

Implementations§

Source§

impl SpecGroup

Source

pub fn new( name: impl Into<String>, members: impl IntoIterator<Item = impl Into<String>>, ) -> Self

A group named name holding members, exclusive and not required — the defaults clap uses.

Source

pub fn required(self) -> Self

The same, but at least one member must be given.

Source

pub fn multiple(self) -> Self

The same, but more than one member may be given.

Source

pub fn usage(&self) -> String

Trait Implementations§

Source§

impl Clone for SpecGroup

Source§

fn clone(&self) -> SpecGroup

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SpecGroup

Source§

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

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

impl Default for SpecGroup

Source§

fn default() -> SpecGroup

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

impl Display for SpecGroup

Source§

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

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

impl From<&SpecGroup> for KdlNode

Source§

fn from(group: &SpecGroup) -> KdlNode

Converts to this type from the input type.
Source§

impl Serialize for SpecGroup

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> 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.