pub struct Span {
pub start: usize,
pub end: usize,
}Expand description
A byte-offset span into the original source buffer. Never owns data; always references the original input.
Fields§
§start: usize§end: usizeImplementations§
Source§impl Span
impl Span
Sourcepub fn new(start: usize, end: usize) -> Span
pub fn new(start: usize, end: usize) -> Span
Construct a span. Panics in both debug and release builds if
start > end, because such a span will inevitably panic later
at slice time and the early panic gives a better error message.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn as_slice<'a>(&self, source: &'a [u8]) -> &'a [u8] ⓘ
pub fn as_slice<'a>(&self, source: &'a [u8]) -> &'a [u8] ⓘ
Borrow the span’s bytes from source. Panics if the span is
out of bounds for source — use Span::try_as_slice when the
caller cannot guarantee bounds.
Sourcepub fn try_as_slice<'a>(&self, source: &'a [u8]) -> Option<&'a [u8]>
pub fn try_as_slice<'a>(&self, source: &'a [u8]) -> Option<&'a [u8]>
Borrow the span’s bytes from source, returning None if the
span lies outside the buffer instead of panicking.
Trait Implementations§
impl Copy for Span
impl Eq for Span
impl StructuralPartialEq for Span
Auto Trait Implementations§
impl Freeze for Span
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnsafeUnpin for Span
impl UnwindSafe for Span
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more