pub struct SpanConverter { /* private fields */ }Expand description
Converter for efficiently handling many spans from the same text.
Pre-computes mapping tables so each conversion is O(1).
Implementations§
Source§impl SpanConverter
impl SpanConverter
Sourcepub fn byte_to_char(&self, byte_idx: usize) -> usize
pub fn byte_to_char(&self, byte_idx: usize) -> usize
Convert byte offset to char offset.
§Arguments
byte_idx- Byte offset in the text
§Returns
Character offset corresponding to the byte offset. If byte_idx is out of bounds,
returns the last valid character index (or 0 if the map is empty).
§Panics
In debug mode, panics if byte_idx exceeds the text length by more than 1
(allowing for the exclusive end position).
Sourcepub fn char_to_byte(&self, char_idx: usize) -> usize
pub fn char_to_byte(&self, char_idx: usize) -> usize
Convert char offset to byte offset.
§Arguments
char_idx- Character offset in the text
§Returns
Byte offset corresponding to the character offset. If char_idx is out of bounds,
returns the last valid byte index (or 0 if the map is empty).
§Panics
In debug mode, panics if char_idx exceeds the character count by more than 1
(allowing for the exclusive end position).
Sourcepub fn from_bytes(&self, byte_start: usize, byte_end: usize) -> TextSpan
pub fn from_bytes(&self, byte_start: usize, byte_end: usize) -> TextSpan
Convert byte span to TextSpan.
Sourcepub fn from_chars(&self, char_start: usize, char_end: usize) -> TextSpan
pub fn from_chars(&self, char_start: usize, char_end: usize) -> TextSpan
Convert char span to TextSpan.
Auto Trait Implementations§
impl Freeze for SpanConverter
impl RefUnwindSafe for SpanConverter
impl Send for SpanConverter
impl Sync for SpanConverter
impl Unpin for SpanConverter
impl UnsafeUnpin for SpanConverter
impl UnwindSafe for SpanConverter
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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