Struct codemap::File

source ·
pub struct File {
    pub span: Span,
    /* private fields */
}
Expand description

A CodeMap’s record of a source file.

Fields§

§span: Span

The span representing the entire file.

Implementations§

source§

impl File

source

pub fn name(&self) -> &str

Gets the name of the file

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 find_line_col(&self, pos: Pos) -> LineCol

Gets the line and column of a Pos.

§Panics
  • If pos is not with this file’s span
  • If pos points to a byte in the middle of a UTF-8 character
source

pub fn source(&self) -> &str

Gets the full source text of the file

source

pub fn source_slice(&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

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.

§Panics
  • If the line number is out of range
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 num_lines(&self) -> usize

Gets the number of lines in the file

Trait Implementations§

source§

impl Debug for File

source§

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

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

impl Hash for File

source§

fn hash<H: Hasher>(&self, hasher: &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 File

source§

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

Compares by identity

1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for File

Auto Trait Implementations§

§

impl Freeze for File

§

impl RefUnwindSafe for File

§

impl Send for File

§

impl Sync for File

§

impl Unpin for File

§

impl UnwindSafe for File

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>,

§

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>,

§

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.