pub struct Index { /* private fields */ }Expand description
An index built for fast convertion between byte offsets and line-column locations.
NOTE: the last element of line_offsets should be considered as a fake offset (sentinel):
self.line_offsets: [line0, line1, ..., EOF]
By the word ‘fake’, we means that if some offset >= the last offset, it should be seen as exceding the index since the last element only marks ending.
§Invariants
indexis never empty.index[0] == 0.indexis monotonically increasing.indexis append-only (no removals or mutations).- A sentinel EOF offset is always present as the last element.
Therefore:
- Valid logical line indices are
0..self.count(), wherecount() = index.len() - 1. - For any valid line
i, the byte range is:[index[i], index[i + 1]).
Implementations§
Source§impl Index
impl Index
Sourcepub fn new() -> Self
pub fn new() -> Self
An index with the first line starting at offset 0, which is the most common usage.
The zero is safe here since it just means an ending, which also means empty.
Sourcepub fn count(&self) -> usize
pub fn count(&self) -> usize
length of index The API has guaranteed that self.line_offsets.len() > 0
Sourcepub fn into_offsets(self) -> Vec<Offset>
pub fn into_offsets(self) -> Vec<Offset>
into vector of offsets
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Index
impl RefUnwindSafe for Index
impl Send for Index
impl Sync for Index
impl Unpin for Index
impl UnsafeUnpin for Index
impl UnwindSafe for Index
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