Skip to content

Commit 403ec11

Browse files
committed
syntax: add 'Repetition::with'
This is useful when doing structural recursion on a '&Hir' to produce a new 'Hir' derived from it.
1 parent 78ca420 commit 403ec11

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

regex-syntax/src/hir/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,19 @@ pub struct Repetition {
17391739
pub sub: Box<Hir>,
17401740
}
17411741

1742+
impl Repetition {
1743+
/// Returns a new repetition with the same `min`, `max` and `greedy`
1744+
/// values, but with its sub-expression replaced with the one given.
1745+
pub fn with(&self, sub: Hir) -> Repetition {
1746+
Repetition {
1747+
min: self.min,
1748+
max: self.max,
1749+
greedy: self.greedy,
1750+
sub: Box::new(sub),
1751+
}
1752+
}
1753+
}
1754+
17421755
/// A type describing the different flavors of `.`.
17431756
///
17441757
/// This type is meant to be used with [`Hir::dot`], which is a convenience

0 commit comments

Comments
 (0)