Struct SourceText

Source
pub struct SourceText { /* private fields */ }
Expand description

A type representing a single identifier that may be referred to by [Span]s.

In most cases, an identifier is a single input file.

Implementations§

Source§

impl SourceText

Source

pub fn snippet<S, N>(text: S, name: N) -> Self
where S: Into<String>, N: Into<Cow<'static, str>>,

Create a snippet with given name

Source

pub fn source_id(&self) -> SourceID

Get the cache id

Source

pub fn get_length(&self) -> usize

Get the length of the total number of characters in the identifier.

Source

pub fn get_line(&self, idx: usize) -> Option<&SourceLine>

Get access to a specific, zero-indexed SourceLine.

Source

pub fn get_source(&self) -> &SourcePath

Get the length of the total number of characters in the identifier.

Source

pub fn set_source(&mut self, path: SourcePath)

Set path name of identifier

Source

pub fn set_path(&mut self, path: &Path)

Set path name of identifier

Source

pub fn with_path(self, path: &Path) -> Self

Get path name of identifier

Source

pub fn set_remote(&mut self, url: Url) -> bool

Set path name of identifier

Source

pub fn with_remote(self, url: Url) -> Self

Get path name of identifier

Source

pub fn text(&self) -> &str

Return the raw text fetch from source

Source

pub fn lines(&self) -> &[SourceLine]

Return an iterator over the SourceLines in this identifier.

Source

pub fn clear(&mut self)

Clear the cache cache

Source§

impl SourceText

Source

pub fn get_offset_line(&self, offset: u32) -> Option<(&SourceLine, usize, u32)>

Get the line that the given offset appears on, and the line/column numbers of the offset.

Note that the line/column numbers are zero-indexed.

Source

pub fn get_line_range(&self, span: &Range<u32>) -> Range<usize>

Get the range of lines that this source_text runs across.

The resulting range is guaranteed to contain valid line indices (i.e: those that can be used for SourceText::get_line).

Trait Implementations§

Source§

impl Clone for SourceText

Source§

fn clone(&self) -> SourceText

Returns a copy 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 SourceText

Source§

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

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

impl<S: Into<String>> From<S> for SourceText

Source§

fn from(source: S) -> Self

Generate a SourceText from the given str.

Note that this function can be expensive for long strings. Use an implementor of [Cache] where possible.

Source§

impl Hash for SourceText

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 SourceText

Source§

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

Tests for self and other values to be equal, and is used by ==.
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 SourceText

Source§

impl StructuralPartialEq for SourceText

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

impl<T> ErasedDestructor for T
where T: 'static,