pub struct Locator<'a> { /* private fields */ }Implementations§
Source§impl<'a> Locator<'a>
impl<'a> Locator<'a>
pub const fn new(contents: &'a str) -> Self
pub fn to_index(&self) -> &LineIndex
pub fn to_source_code(&self) -> SourceCode<'_, '_>
Sourcepub fn floor_char_boundary(&self, offset: TextSize) -> TextSize
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)
);Trait Implementations§
Source§impl LineRanges for Locator<'_>
impl LineRanges for Locator<'_>
Source§fn line_start(&self, offset: TextSize) -> TextSize
fn line_start(&self, offset: TextSize) -> TextSize
Computes the start position of the line of
offset. Read moreSource§fn bom_start_offset(&self) -> TextSize
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
fn full_line_end(&self, offset: TextSize) -> TextSize
Computes the offset that is right after the newline character that ends
offset’s line. Read moreSource§fn line_end(&self, offset: TextSize) -> TextSize
fn line_end(&self, offset: TextSize) -> TextSize
Computes the offset that is right before the newline character that ends
offset’s line. Read moreSource§fn full_line_str(&self, offset: TextSize) -> &str
fn full_line_str(&self, offset: TextSize) -> &str
Returns the text of the
offset’s line. Read moreSource§fn contains_line_break(&self, range: TextRange) -> bool
fn contains_line_break(&self, range: TextRange) -> bool
Returns true if the text of
range contains any line break. Read moreSource§fn lines_str(&self, range: TextRange) -> &str
fn lines_str(&self, range: TextRange) -> &str
Returns the text of all lines that include
range. Read moreSource§fn full_lines_str(&self, range: TextRange) -> &str
fn full_lines_str(&self, range: TextRange) -> &str
Returns the text of all lines that include
range. Read moreSource§fn is_at_start_of_line(&self, offset: TextSize) -> bool
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
fn full_line_range(&self, offset: TextSize) -> TextRange
Computes the range of this
offsets line. Read moreSource§fn line_range(&self, offset: TextSize) -> TextRange
fn line_range(&self, offset: TextSize) -> TextRange
Computes the range of this
offsets line ending before the newline character. Read moreSource§fn full_lines_range(&self, range: TextRange) -> TextRange
fn full_lines_range(&self, range: TextRange) -> TextRange
Computes the range of all lines that this
range covers. Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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