pub struct StrSpan<'a> { /* private fields */ }
Expand description
An immutable string slice.
Unlike &str
contains a reference to the original string
and a span position.
Implementations§
source§impl<'a> StrSpan<'a>
impl<'a> StrSpan<'a>
sourcepub fn from_substr(text: &str, start: usize, end: usize) -> StrSpan<'_>
pub fn from_substr(text: &str, start: usize, end: usize) -> StrSpan<'_>
Constructs a new StrSpan
from substring.
sourcepub fn to_str(&self) -> &'a str
pub fn to_str(&self) -> &'a str
Returns a span slice.
A bit expensive, since Rust checks for char boundary.
sourcepub fn as_bytes(&self) -> &'a [u8] ⓘ
pub fn as_bytes(&self) -> &'a [u8] ⓘ
Returns a span slice as bytes.
The same as to_str
but does not involve char boundary checking.
sourcepub fn slice_region(&self, start: usize, end: usize) -> StrSpan<'a>
pub fn slice_region(&self, start: usize, end: usize) -> StrSpan<'a>
Returns an underling string region as StrSpan
.