pub struct ByteSpan {
pub start: Position,
pub end: u64,
}Expand description
A half-open byte range within a source file, with the start’s line and column.
Spans are retained on every category and value a document holds, which is what lets a write that preserves the original file reproduce untouched values byte for byte instead of re-rendering them.
Fields§
§start: PositionWhere the span begins.
end: u64Offset one past the last byte of the span.
Implementations§
Source§impl ByteSpan
impl ByteSpan
Sourcepub const fn new(start: Position, end: u64) -> Self
pub const fn new(start: Position, end: u64) -> Self
Creates a span running from start up to but excluding end.
§Examples
use molframe_core::{ByteSpan, Position};
let span = ByteSpan::new(Position::new(10, 2, 1), 14);
assert_eq!(span.len(), Some(4));Sourcepub fn slice(self, source: &[u8]) -> Option<&[u8]>
pub fn slice(self, source: &[u8]) -> Option<&[u8]>
Returns the bytes this span covers, or None if it runs past the end of
source.
Returning None rather than clamping matters: a span that does not fit
its buffer means the span and the buffer came from different reads, and
silently truncating would hide that.
Trait Implementations§
impl Copy for ByteSpan
impl Eq for ByteSpan
Source§impl Ord for ByteSpan
impl Ord for ByteSpan
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for ByteSpan
impl PartialOrd for ByteSpan
impl StructuralPartialEq for ByteSpan
Auto Trait Implementations§
impl Freeze for ByteSpan
impl RefUnwindSafe for ByteSpan
impl Send for ByteSpan
impl Sync for ByteSpan
impl Unpin for ByteSpan
impl UnsafeUnpin for ByteSpan
impl UnwindSafe for ByteSpan
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more