Trait bparse::Repetition

source ·
pub trait Repetition {
    // Required methods
    fn lower_bound(&self) -> usize;
    fn upper_bound(&self) -> Option<usize>;
}
Expand description

Trait used to specify start and end bounds for pattern repetitions

Unlike the standard library’s std::ops::RangeBounds,

  1. this trait cannot express an unbounded lower bound
  2. this trait’s bounds are always inclusive

Examples

use bparse::Repetition;

assert_eq!(3.lower_bound(), 3);
assert_eq!(3.upper_bound(), Some(3));

assert_eq!((2..=4).lower_bound(), 2);
assert_eq!((2..=4).upper_bound(), Some(4));

assert_eq!((..=10).lower_bound(), 0);
assert_eq!((..=10).upper_bound(), Some(10));

assert_eq!((3..).lower_bound(), 3);
assert_eq!((3..).upper_bound(), None);

Required Methods§

source

fn lower_bound(&self) -> usize

The minimum amount of times a pattern should repeat

source

fn upper_bound(&self) -> Option<usize>

The maxiumum amount of times a pattern should repeat, possibly unbounded.

Implementations on Foreign Types§

source§

impl Repetition for usize

source§

impl Repetition for RangeFrom<usize>

source§

impl Repetition for RangeInclusive<usize>

source§

impl Repetition for RangeToInclusive<usize>

Implementors§