mf2_parser

Struct SourceTextInfo

source
pub struct SourceTextInfo<'text> { /* private fields */ }
Expand description

A view onto the source text, with additional information about the source text that was derived during parsing.

This struct provides methods to convert between opaque Location values, UTF-8 line and column indices, and UTF-16 line and column indices. It also provides methods to calculate the length of a span in UTF-8 bytes or UTF-16 code units.

Implementations§

source§

impl SourceTextInfo<'_>

source

pub fn utf8_line_col(&self, loc: Location) -> LineColUtf8

Returns a UTF-8 line and column index pair given a Location.

It is undefined behavior to pass a location that is out of bounds for the source text.

source

pub fn utf16_line_col(&self, loc: Location) -> LineColUtf16

Returns a UTF-16 line and column index pair given a Location.

It is undefined behavior to pass a location that is out of bounds for the source text.

source

pub fn utf8_len(&self, span: Span) -> u32

Returns the length of the given span in UTF-8 bytes.

source

pub fn utf16_len(&self, span: Span) -> u32

Returns the length of the given span in UTF-16 code units.

source

pub fn utf8_loc(&self, line_col: LineColUtf8) -> Location

Returns the location of the given UTF-8 line and column index pair.

If the line index is out of bounds, returns a location pointing to the end of the source text.

If the column index is greater than the line length, it is clamped to the line length. If the column index points to within a multi-byte character, the location will point to the the start of that character.

source

pub fn utf16_loc(&self, line_col: LineColUtf16) -> Location

Returns the location of the given UTF-16 line and column index pair.

If the line index is out of bounds, returns a location pointing to the end of the source text.

If the column index is greater than the line length, it is clamped to the line length. If the column index points to within a multi-byte character, the location will point to the the start of that character.

Trait Implementations§

Auto Trait Implementations§

§

impl<'text> Freeze for SourceTextInfo<'text>

§

impl<'text> RefUnwindSafe for SourceTextInfo<'text>

§

impl<'text> Send for SourceTextInfo<'text>

§

impl<'text> Sync for SourceTextInfo<'text>

§

impl<'text> Unpin for SourceTextInfo<'text>

§

impl<'text> UnwindSafe for SourceTextInfo<'text>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.