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>) -> Self
pub fn new(range: impl RangeBounds<usize>) -> Self
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) -> Self
fn from(quantifier: Quantifier) -> Self
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