Struct Span

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

A span that records source code locations.

Used to print error messages.

Implementations§

Source§

impl Span

Source

pub fn new(file_type: FileType) -> Self

Creates a new span.

Source

pub fn log_raw_error(&self, args: Arguments<'_>) -> Error

Available on crate feature logger only.

Logs normal error with no span provided.

Source

pub fn log_raw_fatal_error(&self, args: Arguments<'_>) -> Error

Available on crate feature logger only.

Logs fatal error with no span provided.

Source

pub fn log_raw_warning(&self, args: Arguments<'_>)

Available on crate feature logger only.

Logs warning with no span provided.

Source

pub fn log_summary(&self)

Available on crate feature logger only.

Logs summary information (total error/warning number).

Source

pub fn file_type(&self) -> &FileType

Returns a reference to the file type.

Source

pub fn error_num(&self) -> usize

Gets the number of errors.

Source

pub fn warning_num(&self) -> usize

Gets the number of warnings.

Source

pub fn log_error(&self, args: Arguments<'_>) -> Error

Available on crate feature logger only.

Logs normal error message.

Source

pub fn log_fatal_error(&self, args: Arguments<'_>) -> Error

Available on crate feature logger only.

Logs fatal error message.

Source

pub fn log_warning(&self, args: Arguments<'_>)

Available on crate feature logger only.

Logs warning message.

Source

pub fn start(&self) -> Location

Returns the start location of the span.

Source

pub fn end(&self) -> Location

Returns the end location of the span.

Source

pub fn update<C>(&mut self, c: &C)
where C: LocationUpdate,

Updates the line number ans column number of the start location based on the given character, then set the end location to the start position.

§Examples
use laps::span::{FileType, Span};

let mut span = Span::new(FileType::Buffer);
assert_eq!(format!("{span}"), "1:0-1:0");
span.update(&' ');
assert_eq!(format!("{span}"), "1:1-1:1");
span.update(&'\n');
assert_eq!(format!("{span}"), "2:0-2:0");
Source

pub fn into_updated<C>(self, c: &C) -> Self
where C: LocationUpdate,

Converts the current span into a new one where the location has been updated.

Source

pub fn update_loc(&mut self, loc: Location)

Updates both the start and the end location to the given location.

Source

pub fn update_end<S>(&mut self, span: S)
where S: AsRef<Self>,

Updates the end location according to the given span.

§Examples
use laps::span::{FileType, Span};

let mut span = Span::new(FileType::Buffer);
span.update_end(&span.clone().into_updated(&'\n'));
assert_eq!(format!("{span}"), "1:0-2:0");
Source

pub fn into_end_updated<S>(self, span: S) -> Self
where S: AsRef<Self>,

Converts the current span into a new one where the end location has been updated according to the given span.

Source

pub fn is_in_same_line_as<S>(&self, span: S) -> bool
where S: AsRef<Self>,

Checks if the current span is in the same line as the given span.

§Examples
use laps::span::{FileType, Span};

let span = Span::new(FileType::Buffer);
let span2 = span.clone().into_updated(&' ');
assert!(span.is_in_same_line_as(&span2));
let span3 = span.clone().into_updated(&'\n');
assert!(!span.is_in_same_line_as(&span3));

Trait Implementations§

Source§

impl AsRef<Span> for Span

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Span

Source§

fn clone(&self) -> Span

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 Span

Source§

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

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

impl Display for Span

Source§

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

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

impl PartialEq for Span

Source§

fn eq(&self, other: &Self) -> 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 Span

Auto Trait Implementations§

§

impl Freeze for Span

§

impl RefUnwindSafe for Span

§

impl Send for Span

§

impl Sync for Span

§

impl Unpin for Span

§

impl UnwindSafe for Span

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.