pub struct ArgCount { /* private fields */ }Expand description
Represents the number of values an argument takes.
Implementations§
Source§impl ArgCount
impl ArgCount
Sourcepub fn new(min: Option<usize>, max: Option<usize>) -> Self
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.
Sourcepub fn new_bounded(min: usize, max: usize) -> Self
pub fn new_bounded(min: usize, max: usize) -> Self
Sourcepub const fn exactly(count: usize) -> Self
pub const fn exactly(count: usize) -> Self
Constructs a new ArgCount for the specified number of values.
Sourcepub fn more_than(min: usize) -> Self
pub fn more_than(min: usize) -> Self
Constructs a new ArgCount for more than the specified number of values.
Sourcepub fn less_than(max: usize) -> Self
pub fn less_than(max: usize) -> Self
Constructs a new ArgCount for less than the specified number of values.
Sourcepub const fn min_or_default(&self) -> usize
pub const fn min_or_default(&self) -> usize
Returns the min number of values if bounded or usize::MIN if unbounded.
Sourcepub const fn max_or_default(&self) -> usize
pub const fn max_or_default(&self) -> usize
Returns the max number of values if bounded or usize::MAX if unbounded.
Sourcepub const fn min(&self) -> Option<usize>
pub const fn min(&self) -> Option<usize>
Returns the min number of values or None if unbounded.
Sourcepub const fn max(&self) -> Option<usize>
pub const fn max(&self) -> Option<usize>
Returns the max number of values of None if unbounded.
Sourcepub const fn takes(&self, count: usize) -> bool
pub const fn takes(&self, count: usize) -> bool
Returns true if this takes the provided number of values.
Sourcepub const fn takes_values(&self) -> bool
pub const fn takes_values(&self) -> bool
Returns true if this takes values.
Sourcepub const fn takes_exactly(&self, count: usize) -> bool
pub const fn takes_exactly(&self, count: usize) -> bool
Returns true if this takes exactly the specified number of values.