use syntax::codemap::{Span, BytePos};
pub trait SpanExt {
fn trim(self, length: u32) -> Span;
fn trim_left(self, length: usize) -> Span;
fn trim_right(self, length: usize) -> Span;
fn shorten_to(self, to_length: usize) -> Span;
fn shorten_upto(self, length: usize) -> Span;
}
impl SpanExt for Span {
fn trim_left(self, length: usize) -> Span {
self.with_lo(self.lo() + BytePos(length as u32))
}
fn trim_right(self, length: usize) -> Span {
self.with_hi(self.hi() - BytePos(length as u32))
}
fn shorten_to(self, to_length: usize) -> Span {
self.with_hi(self.lo() + BytePos(to_length as u32))
}
fn shorten_upto(self, length: usize) -> Span {
self.with_lo(self.hi() - BytePos(length as u32))
}
fn trim(self, length: u32) -> Span {
self.with_lo(self.lo() + BytePos(length))
.with_hi(self.hi() - BytePos(length))
}
}