CodeMap

Struct CodeMap 

Source
pub struct CodeMap(/* private fields */);
Expand description

A data structure recording a source code file for position lookup.

Implementations§

Source§

impl CodeMap

Source

pub fn new(filename: String, source: String) -> CodeMap

Creates an new CodeMap.

Source

pub fn empty_static() -> &'static CodeMap

Source

pub fn id(&self) -> CodeMapId

Only used internally for profiling optimisations

Source

pub fn full_span(&self) -> Span

Source

pub fn file_span(&self, span: Span) -> FileSpan

Gets the file and its line and column ranges represented by a Span.

Source

pub fn filename(&self) -> &str

Gets the name of the file

Source

pub fn byte_at(&self, pos: Pos) -> u8

Source

pub fn find_line(&self, pos: Pos) -> usize

Gets the line number of a Pos.

The lines are 0-indexed (first line is numbered 0)

Panics if pos is not within this file’s span.

Source

pub fn source(&self) -> &str

Gets the full source text of the file

Source

pub fn source_span(&self, span: Span) -> &str

Gets the source text of a Span.

Panics if span is not entirely within this file.

Source

pub fn line_span(&self, line: usize) -> Span

Like line_span_opt but panics if the line number is out of range.

Source

pub fn line_span_trim_newline(&self, line: usize) -> Span

Trim trailing newline if any, including windows, from the line span.

Source

pub fn line_span_opt(&self, line: usize) -> Option<Span>

Gets the span representing a line by line number.

The line number is 0-indexed (first line is numbered 0). The returned span includes the line terminator.

Returns None if the number if out of range.

Source

pub fn resolve_span(&self, span: Span) -> ResolvedSpan

Source

pub fn source_line(&self, line: usize) -> &str

Gets the source text of a line.

The string returned does not include the terminating \r or \n characters.

Panics if the line number is out of range.

Source

pub fn source_line_at_pos(&self, pos: Pos) -> &str

Trait Implementations§

Source§

impl Allocative for CodeMap

Source§

fn visit<'allocative_a, 'allocative_b: 'allocative_a>( &self, visitor: &'allocative_a mut Visitor<'allocative_b>, )

Source§

impl Clone for CodeMap

Source§

fn clone(&self) -> CodeMap

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for CodeMap

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CodeMap

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Dupe for CodeMap

Source§

fn dupe(&self) -> Self

Source§

impl Hash for CodeMap

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CodeMap

Source§

fn eq(&self, other: &Self) -> bool

Compares by identity

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for CodeMap

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToAst for T

Source§

fn ast(self, begin: usize, end: usize) -> Spanned<Self>

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 = 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.