Struct ArgCount

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

Represents the number of values an argument takes.

Implementations§

Source§

impl ArgCount

Source

pub fn new(min: Option<usize>, max: Option<usize>) -> Self

Constructs a new ArgCount with the given min and max. It takes Option<usize> where Some(usize) is bounded and None is unbounded.

§Example
use clapi::ArgCount;

// This goes from 2 to the usize::MAX
let unbounded_max = ArgCount::new(Some(2), None);
assert_eq!(unbounded_max.min_or_default(), 2);
assert_eq!(unbounded_max.max_or_default(), usize::MAX);

// This goes from usize::MIN to 12
let unbounded_min = ArgCount::new(None, Some(12));
assert_eq!(unbounded_min.min_or_default(), usize::MIN);
assert_eq!(unbounded_min.max_or_default(), 12);

// This goes from 5 to 10
let bounded = ArgCount::new(Some(5), Some(10));
assert_eq!(bounded.min_or_default(), 5);
assert_eq!(bounded.max_or_default(), 10);
§Panics

If min > max.

Source

pub fn new_bounded(min: usize, max: usize) -> Self

Constructs a new ArgCount with a know min and max

§Example
use clapi::ArgCount;

let count = ArgCount::new_bounded(2, 10);
assert_eq!(count.min_or_default(), 2);
assert_eq!(count.max_or_default(), 10);
§Panics

If min > max

Source

pub const fn zero() -> Self

Constructs a new ArgCount for not values.

Source

pub const fn one() -> Self

Constructs a new ArgCount for exactly 1 values.

Source

pub const fn any() -> Self

Constructs a new ArgCount for any number of values.

Source

pub const fn exactly(count: usize) -> Self

Constructs a new ArgCount for the specified number of values.

Source

pub fn more_than(min: usize) -> Self

Constructs a new ArgCount for more than the specified number of values.

Source

pub fn less_than(max: usize) -> Self

Constructs a new ArgCount for less than the specified number of values.

Source

pub const fn min_or_default(&self) -> usize

Returns the min number of values if bounded or usize::MIN if unbounded.

Source

pub const fn max_or_default(&self) -> usize

Returns the max number of values if bounded or usize::MAX if unbounded.

Source

pub const fn min(&self) -> Option<usize>

Returns the min number of values or None if unbounded.

Source

pub const fn max(&self) -> Option<usize>

Returns the max number of values of None if unbounded.

Source

pub fn with_min(&self, min: usize) -> Self

Returns a copy of this ArgCount with the given min.

Source

pub fn with_max(&self, max: usize) -> Self

Returns a copy of this ArgCount with the given max.

Source

pub const fn takes(&self, count: usize) -> bool

Returns true if this takes the provided number of values.

Source

pub const fn takes_values(&self) -> bool

Returns true if this takes values.

Source

pub const fn is_exact(&self) -> bool

Returns true if this takes an exact number of values.

Source

pub const fn takes_exactly(&self, count: usize) -> bool

Returns true if this takes exactly the specified number of values.

Trait Implementations§

Source§

impl Clone for ArgCount

Source§

fn clone(&self) -> ArgCount

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 ArgCount

Source§

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

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

impl Default for ArgCount

Source§

fn default() -> ArgCount

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

impl Display for ArgCount

Source§

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

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

impl From<ArgCount> for RangeInclusive<usize>

Source§

fn from(arg_count: ArgCount) -> Self

Converts to this type from the input type.
Source§

impl From<Range<i128>> for ArgCount

Source§

fn from(value: Range<i128>) -> Self

Converts to this type from the input type.
Source§

impl From<Range<i16>> for ArgCount

Source§

fn from(value: Range<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<Range<i32>> for ArgCount

Source§

fn from(value: Range<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<Range<i64>> for ArgCount

Source§

fn from(value: Range<i64>) -> Self

Converts to this type from the input type.
Source§

impl From<Range<i8>> for ArgCount

Source§

fn from(value: Range<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<Range<isize>> for ArgCount

Source§

fn from(value: Range<isize>) -> Self

Converts to this type from the input type.
Source§

impl From<Range<u128>> for ArgCount

Source§

fn from(value: Range<u128>) -> Self

Converts to this type from the input type.
Source§

impl From<Range<u16>> for ArgCount

Source§

fn from(value: Range<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Range<u32>> for ArgCount

Source§

fn from(value: Range<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Range<u64>> for ArgCount

Source§

fn from(value: Range<u64>) -> Self

Converts to this type from the input type.
Source§

impl From<Range<u8>> for ArgCount

Source§

fn from(value: Range<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Range<usize>> for ArgCount

Source§

fn from(value: Range<usize>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeFrom<i128>> for ArgCount

Source§

fn from(value: RangeFrom<i128>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeFrom<i16>> for ArgCount

Source§

fn from(value: RangeFrom<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeFrom<i32>> for ArgCount

Source§

fn from(value: RangeFrom<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeFrom<i64>> for ArgCount

Source§

fn from(value: RangeFrom<i64>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeFrom<i8>> for ArgCount

Source§

fn from(value: RangeFrom<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeFrom<isize>> for ArgCount

Source§

fn from(value: RangeFrom<isize>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeFrom<u128>> for ArgCount

Source§

fn from(value: RangeFrom<u128>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeFrom<u16>> for ArgCount

Source§

fn from(value: RangeFrom<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeFrom<u32>> for ArgCount

Source§

fn from(value: RangeFrom<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeFrom<u64>> for ArgCount

Source§

fn from(value: RangeFrom<u64>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeFrom<u8>> for ArgCount

Source§

fn from(value: RangeFrom<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeFrom<usize>> for ArgCount

Source§

fn from(value: RangeFrom<usize>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeFull> for ArgCount

Source§

fn from(_: RangeFull) -> Self

Converts to this type from the input type.
Source§

impl From<RangeInclusive<i128>> for ArgCount

Source§

fn from(value: RangeInclusive<i128>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeInclusive<i16>> for ArgCount

Source§

fn from(value: RangeInclusive<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeInclusive<i32>> for ArgCount

Source§

fn from(value: RangeInclusive<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeInclusive<i64>> for ArgCount

Source§

fn from(value: RangeInclusive<i64>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeInclusive<i8>> for ArgCount

Source§

fn from(value: RangeInclusive<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeInclusive<isize>> for ArgCount

Source§

fn from(value: RangeInclusive<isize>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeInclusive<u128>> for ArgCount

Source§

fn from(value: RangeInclusive<u128>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeInclusive<u16>> for ArgCount

Source§

fn from(value: RangeInclusive<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeInclusive<u32>> for ArgCount

Source§

fn from(value: RangeInclusive<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeInclusive<u64>> for ArgCount

Source§

fn from(value: RangeInclusive<u64>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeInclusive<u8>> for ArgCount

Source§

fn from(value: RangeInclusive<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeInclusive<usize>> for ArgCount

Source§

fn from(value: RangeInclusive<usize>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeTo<i128>> for ArgCount

Source§

fn from(value: RangeTo<i128>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeTo<i16>> for ArgCount

Source§

fn from(value: RangeTo<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeTo<i32>> for ArgCount

Source§

fn from(value: RangeTo<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeTo<i64>> for ArgCount

Source§

fn from(value: RangeTo<i64>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeTo<i8>> for ArgCount

Source§

fn from(value: RangeTo<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeTo<isize>> for ArgCount

Source§

fn from(value: RangeTo<isize>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeTo<u128>> for ArgCount

Source§

fn from(value: RangeTo<u128>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeTo<u16>> for ArgCount

Source§

fn from(value: RangeTo<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeTo<u32>> for ArgCount

Source§

fn from(value: RangeTo<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeTo<u64>> for ArgCount

Source§

fn from(value: RangeTo<u64>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeTo<u8>> for ArgCount

Source§

fn from(value: RangeTo<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeTo<usize>> for ArgCount

Source§

fn from(value: RangeTo<usize>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeToInclusive<i128>> for ArgCount

Source§

fn from(value: RangeToInclusive<i128>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeToInclusive<i16>> for ArgCount

Source§

fn from(value: RangeToInclusive<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeToInclusive<i32>> for ArgCount

Source§

fn from(value: RangeToInclusive<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeToInclusive<i64>> for ArgCount

Source§

fn from(value: RangeToInclusive<i64>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeToInclusive<i8>> for ArgCount

Source§

fn from(value: RangeToInclusive<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeToInclusive<isize>> for ArgCount

Source§

fn from(value: RangeToInclusive<isize>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeToInclusive<u128>> for ArgCount

Source§

fn from(value: RangeToInclusive<u128>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeToInclusive<u16>> for ArgCount

Source§

fn from(value: RangeToInclusive<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeToInclusive<u32>> for ArgCount

Source§

fn from(value: RangeToInclusive<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeToInclusive<u64>> for ArgCount

Source§

fn from(value: RangeToInclusive<u64>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeToInclusive<u8>> for ArgCount

Source§

fn from(value: RangeToInclusive<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<RangeToInclusive<usize>> for ArgCount

Source§

fn from(value: RangeToInclusive<usize>) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for ArgCount

Source§

fn from(value: i128) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for ArgCount

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for ArgCount

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for ArgCount

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for ArgCount

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for ArgCount

Source§

fn from(value: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for ArgCount

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for ArgCount

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for ArgCount

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for ArgCount

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for ArgCount

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for ArgCount

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl Hash for ArgCount

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ArgCount

Source§

fn eq(&self, other: &ArgCount) -> 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 RangeBounds<usize> for ArgCount

Source§

fn start_bound(&self) -> Bound<&usize>

Start index bound. Read more
Source§

fn end_bound(&self) -> Bound<&usize>

End index bound. Read more
1.35.0 · Source§

fn contains<U>(&self, item: &U) -> bool
where T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
Source§

fn is_empty(&self) -> bool
where T: PartialOrd,

🔬This is a nightly-only experimental API. (range_bounds_is_empty)
Returns true if the range contains no items. One-sided ranges (RangeFrom, etc) always return false. Read more
Source§

impl Copy for ArgCount

Source§

impl Eq for ArgCount

Source§

impl StructuralPartialEq for ArgCount

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