1
Fork 0

Add Span::trim_end

This is the counterpart of `Span::trim_start`.
This commit is contained in:
Zalathar 2024-06-03 17:00:10 +10:00
parent e609c9b254
commit df96cba432
2 changed files with 26 additions and 0 deletions

View file

@ -682,6 +682,13 @@ impl Span {
if span.hi > other.hi { Some(span.with_lo(cmp::max(span.lo, other.hi))) } else { None }
}
/// Returns `Some(span)`, where the end is trimmed by the start of `other`.
pub fn trim_end(self, other: Span) -> Option<Span> {
let span = self.data();
let other = other.data();
if span.lo < other.lo { Some(span.with_hi(cmp::min(span.hi, other.lo))) } else { None }
}
/// Returns the source span -- this is either the supplied span, or the span for
/// the macro callsite that expanded to it.
pub fn source_callsite(self) -> Span {