pub struct Interval { /* private fields */ }Expand description
Represents an inclusive interval with a minimum value and an optional maximum value.
When the maximum is None, the interval is considered unbounded above.
Implementations§
Source§impl Interval
impl Interval
Sourcepub fn new(range: impl RangeBounds<usize>) -> Interval
pub fn new(range: impl RangeBounds<usize>) -> Interval
Creates a new Interval from any type that implements
RangeBounds<usize>.
This allows creating intervals from Rust’s range expressions like
1..5, 0..=10, or 2...
Sourcepub fn max(&self) -> Option<usize>
pub fn max(&self) -> Option<usize>
Returns the maximum value of the interval, or None if the interval is
unbounded.
Sourcepub fn contains(&self, count: usize) -> bool
pub fn contains(&self, count: usize) -> bool
Checks if the given count falls within this interval.
Sourcepub fn is_single(&self) -> bool
pub fn is_single(&self) -> bool
Checks if the interval represents a single value (i.e., min equals max).
Sourcepub fn is_unbounded(&self) -> bool
pub fn is_unbounded(&self) -> bool
Checks if the interval is unbounded (i.e., has no maximum value).
Sourcepub fn range_notation(&self) -> String
pub fn range_notation(&self) -> String
Returns a string representation of the interval using standard range notation.
Examples:
{3}for the single value 3{1,5}for the range 1 to 5 inclusive{2,}for 2 or more
Sourcepub fn shorthand_notation(&self) -> String
pub fn shorthand_notation(&self) -> String
Returns a string representation of the interval using shorthand notation where applicable.
Examples:
?for{0,1}(optional)*for{0,}(zero or more)+for{1,}(one or more)
Trait Implementations§
Source§impl Display for Interval
Implements the Display trait for Interval, using the range_notation
format.
impl Display for Interval
Implements the Display trait for Interval, using the range_notation
format.
Source§impl From<Quantifier> for Interval
impl From<Quantifier> for Interval
Source§fn from(quantifier: Quantifier) -> Interval
fn from(quantifier: Quantifier) -> Interval
Source§impl RangeBounds<usize> for Interval
Implementation of RangeBounds<usize> for Interval, allowing it to be
used in contexts that expect range bounds, such as slice indexing.
impl RangeBounds<usize> for Interval
Implementation of RangeBounds<usize> for Interval, allowing it to be
used in contexts that expect range bounds, such as slice indexing.
Source§fn start_bound(&self) -> Bound<&usize>
fn start_bound(&self) -> Bound<&usize>
Returns the start bound of the interval.
- Returns
Bound::Unboundedifminis 0 - Returns
Bound::Included(&self.min)otherwise
Source§fn end_bound(&self) -> Bound<&usize>
fn end_bound(&self) -> Bound<&usize>
Returns the end bound of the interval.
- Returns
Bound::Included(max)ifmaxisSome - Returns
Bound::UnboundedifmaxisNone
impl Copy for Interval
impl Eq for Interval
impl StructuralPartialEq for Interval
Auto Trait Implementations§
impl Freeze for Interval
impl RefUnwindSafe for Interval
impl Send for Interval
impl Sync for Interval
impl Unpin for Interval
impl UnwindSafe for Interval
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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