Skip to main content

Location

Struct Location 

Source
pub struct Location<'a> { /* private fields */ }
Expand description

A source indexed as vfile-location reads it: offsets in UTF-16 code units, turned into lines, columns and the byte points of core’s positions, each in constant or log time.

Implementations§

Source§

impl<'a> Location<'a>

Source

pub fn new(source: &'a str) -> Self

Source

pub fn source(&self) -> &'a str

Source

pub fn len(&self) -> usize

The source’s length in UTF-16 code units.

Source

pub fn is_empty(&self) -> bool

Source

pub fn to_unit(&self, byte: usize) -> usize

The UTF-16 offset of a byte offset, inside a character counting as its start.

Source

pub fn to_byte(&self, unit: usize) -> Option<usize>

The byte offset of a UTF-16 offset, unless it is past the end or inside a pair.

Source

pub fn to_unist_point(&self, point: Point) -> UnistPoint

The unist point of a byte point, as Lines gives it, with its UTF-16 offset.

Source

pub fn to_point(&self, unit: usize) -> Option<UnistPoint>

vfile-location’s toPoint: the point at a UTF-16 offset, unless past the end.

Source

pub fn to_offset(&self, line: usize, column: usize) -> Option<usize>

vfile-location’s toOffset: the UTF-16 offset of a line and column, unless the column is past its line.

Source

pub fn to_position<'b>( &self, start: usize, end: usize, alloc: &'b Allocator, ) -> Option<Position<'b>>

The position of a span of UTF-16 offsets: byte points when both ends start a character, unist points otherwise, none when either is past the end.

Source

pub fn place_nlcst<'b>( &self, nodes: &mut [Node<'b>], start: Option<usize>, alloc: &'b Allocator, ) -> Option<usize>

Place nlcst nodes one after another from a UTF-16 offset, as mdast-util-to-nlcst’s and hast-util-to-nlcst’s patch do: each spans its text’s length, and a node without a start or past the end has no position. The offset after them.

Source

pub fn join<'b>( &self, start: &Position<'b>, end: &Position<'b>, alloc: &'b Allocator, ) -> Position<'b>

The position from one’s start to another’s end, as unist-util-position reads them.

Trait Implementations§

Source§

impl<'a> Clone for Location<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Location<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Location<'a>

§

impl<'a> RefUnwindSafe for Location<'a>

§

impl<'a> Send for Location<'a>

§

impl<'a> Sync for Location<'a>

§

impl<'a> Unpin for Location<'a>

§

impl<'a> UnsafeUnpin for Location<'a>

§

impl<'a> UnwindSafe for Location<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.