Skip to main content

Locator

Struct Locator 

Source
pub struct Locator<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Locator<'a>

Source

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

Source

pub fn to_index(&self) -> &LineIndex

Source

pub fn to_source_code(&self) -> SourceCode<'_, '_>

Source

pub fn floor_char_boundary(&self, offset: TextSize) -> TextSize

Finds the closest TextSize not exceeding the offset for which is_char_boundary is true.

§Examples

let locator = Locator::new("Hello");

assert_eq!(
    locator.floor_char_boundary(TextSize::from(0)),
    TextSize::from(0)
);

assert_eq!(
    locator.floor_char_boundary(TextSize::from(5)),
    TextSize::from(5)
);

let locator = Locator::new("α");

assert_eq!(
    locator.floor_char_boundary(TextSize::from(0)),
    TextSize::from(0)
);

assert_eq!(
    locator.floor_char_boundary(TextSize::from(1)),
    TextSize::from(0)
);

assert_eq!(
    locator.floor_char_boundary(TextSize::from(2)),
    TextSize::from(2)
);
Source

pub const fn contents(&self) -> &'a str

Return the underlying source code.

Trait Implementations§

Source§

impl<'a> Debug for Locator<'a>

Source§

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

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

impl LineRanges for Locator<'_>

Source§

fn line_start(&self, offset: TextSize) -> TextSize

Computes the start position of the line of offset. Read more
Source§

fn bom_start_offset(&self) -> TextSize

Computes the start position of the file contents: either the first byte, or the byte after the BOM.
Source§

fn full_line_end(&self, offset: TextSize) -> TextSize

Computes the offset that is right after the newline character that ends offset’s line. Read more
Source§

fn line_end(&self, offset: TextSize) -> TextSize

Computes the offset that is right before the newline character that ends offset’s line. Read more
Source§

fn full_line_str(&self, offset: TextSize) -> &str

Returns the text of the offset’s line. Read more
Source§

fn line_str(&self, offset: TextSize) -> &str

Returns the text of the offset’s line. Read more
Source§

fn contains_line_break(&self, range: TextRange) -> bool

Returns true if the text of range contains any line break. Read more
Source§

fn lines_str(&self, range: TextRange) -> &str

Returns the text of all lines that include range. Read more
Source§

fn full_lines_str(&self, range: TextRange) -> &str

Returns the text of all lines that include range. Read more
Source§

fn is_at_start_of_line(&self, offset: TextSize) -> bool

Returns true if offset is at the start of a line.
Source§

fn full_line_range(&self, offset: TextSize) -> TextRange

Computes the range of this offsets line. Read more
Source§

fn line_range(&self, offset: TextSize) -> TextRange

Computes the range of this offsets line ending before the newline character. Read more
Source§

fn full_lines_range(&self, range: TextRange) -> TextRange

Computes the range of all lines that this range covers. Read more
Source§

fn lines_range(&self, range: TextRange) -> TextRange

Computes the range of all lines that this range covers. Read more
Source§

fn count_lines(&self, range: TextRange) -> u32

The number of lines range spans. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for Locator<'a>

§

impl<'a> !RefUnwindSafe for Locator<'a>

§

impl<'a> !Sync for Locator<'a>

§

impl<'a> Send for Locator<'a>

§

impl<'a> Unpin for Locator<'a>

§

impl<'a> UnsafeUnpin for Locator<'a>

§

impl<'a> UnwindSafe for Locator<'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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Lookup<T> for T

Source§

fn into_owned(self) -> T

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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more