pub struct Span {
pub start: SpanValue,
pub end: SpanValue,
}Expand description
The Span type represents an area of a file.
Fields§
§start: SpanValueThe start of the Span (Inclusive)
end: SpanValueThe end of the Span (Exclusive)
Implementations§
Source§impl Span
impl Span
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Span. This span will start and end at the 0th character, making it have a length of zero.
Sourcepub fn new_from(start: SpanValue, end: SpanValue) -> Self
pub fn new_from(start: SpanValue, end: SpanValue) -> Self
Creates a new Span from a pair of start and end indexes.
§Panics
Panics if start is greater than end, since spans can’t have a negative length.
Sourcepub fn grow_front(&mut self, amount: SpanValue)
pub fn grow_front(&mut self, amount: SpanValue)
Grows the span from the front. This moves the end value up by amount.
Sourcepub fn with_grow_front(&self, amount: SpanValue) -> Self
pub fn with_grow_front(&self, amount: SpanValue) -> Self
Returns a span that is grown from the front. This moves the end value up by amount.
Sourcepub fn grow_back(&mut self, amount: SpanValue)
pub fn grow_back(&mut self, amount: SpanValue)
Grows the span from the back. This moves the start value back by amount.
§Panics
Panics if the start of the span is less than amount, since spans can’t have a negative start value,
Sourcepub fn with_grow_back(&self, amount: SpanValue) -> Self
pub fn with_grow_back(&self, amount: SpanValue) -> Self
Returns a span that is grown from the back. This moves the start value back by amount.
§Panics
Panics if the start of the span is less than amount, since spans can’t have a negative start value,
Sourcepub fn shrink_back(&mut self, amount: SpanValue)
pub fn shrink_back(&mut self, amount: SpanValue)
Shrinks the span from the back. This moves the start value up by amount.
§Panics
Panics if the size of the Span is less than amount, since a Span’s size can’t be negative.
Sourcepub fn with_shrink_back(&self, amount: SpanValue) -> Self
pub fn with_shrink_back(&self, amount: SpanValue) -> Self
Returns a span that is shrunk from the back. This moves the start value up by amount.
§Panics
Panics if the size of the Span is less than amount, since a Span’s size can’t be negative.
Sourcepub fn shrink_front(&mut self, amount: SpanValue)
pub fn shrink_front(&mut self, amount: SpanValue)
Shrinks the span from the front. This moves the end value back by amount.
§Panics
This method will panic if the size of the Span is less than amount, since a Span’s size can’t be negative.
Sourcepub fn with_shrink_front(&self, amount: SpanValue) -> Self
pub fn with_shrink_front(&self, amount: SpanValue) -> Self
Returns a span shrunk from the front. This moves the end value back by amount.
§Panics
This method will panic if the size of the Span is less than amount, since a Span’s size can’t be negative.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if a Span’s size is 0. Returns true if 0, and false if anything else.
Sourcepub fn reset(&mut self) -> Self
pub fn reset(&mut self) -> Self
Resets self by changing the start to be the end, plus 1, and changing the end to be the start.
The function also returns the old span.
Sourcepub fn apply<'a>(&self, string: &'a str) -> &'a str
pub fn apply<'a>(&self, string: &'a str) -> &'a str
Applies the span to string, with start and end corresponding to char indexes.
§Panics
Panics if string is shorter than the end of the span.
Sourcepub fn apply_bytes<'a>(&self, string: &'a str) -> &'a str
pub fn apply_bytes<'a>(&self, string: &'a str) -> &'a str
Applies the span to string, with start and end corresponding to byte indexes.
§Panics
Panics if string is shorter than the end of the span.