[−][src]Struct asciifile::position::Position
Methods
impl<'t> Position<'t>
[src]
impl<'t> Position<'t>
pub fn at_file_start(file: &'t AsciiFile<'t>) -> Option<Self>
[src]
pub fn at_file_start(file: &'t AsciiFile<'t>) -> Option<Self>
Create a new Position object pointing at the first character
of a file. Returns None
for empty files.
pub fn to_single_char_span(self) -> Span<'t>
[src]
pub fn to_single_char_span(self) -> Span<'t>
pub fn byte_offset(&self) -> usize
[src]
pub fn byte_offset(&self) -> usize
pub fn file(&self) -> &AsciiFile<'t>
[src]
pub fn file(&self) -> &AsciiFile<'t>
pub fn chr(&self) -> char
[src]
pub fn chr(&self) -> char
Get the character at this position
Guranteed to be within the ASCII range of UTF-8 that does not use the
upper half of the bytes. Use byte()
if you need a single
byte representation instead.
pub fn byte(&self) -> u8
[src]
pub fn byte(&self) -> u8
Get the byte at this position
For matching on the character or comparisons, you probably want chr()
instead.
pub fn row(&self) -> usize
[src]
pub fn row(&self) -> usize
Return the row of the character's position within the file.
The row is zero based, meaning characters on the first line
of the file are in row 0
. To get the line number, add 1
to
the return value.
pub fn line_number(&self) -> usize
[src]
pub fn line_number(&self) -> usize
Return the character's line number.
Identical to row() + 1
pub fn column(&self) -> usize
[src]
pub fn column(&self) -> usize
Return the column of the characters position within the file.
The column is zero based, meaning the first characters of
a line/row is positioned at column 0
.
pub fn row_and_column(&self) -> (usize, usize)
[src]
pub fn row_and_column(&self) -> (usize, usize)
Return the column of the characters position within the file.
The column is zero based, meaning the first characters of
a line/row is positioned at column 0
.
pub fn next(&self) -> Option<Position<'t>>
[src]
pub fn next(&self) -> Option<Position<'t>>
Get the position immediatly following this position or None
if
this is the last position in the file.
pub fn next_mut(self) -> Result<Self, Self>
[src]
pub fn next_mut(self) -> Result<Self, Self>
The same as next()
but in-place.
Fails if there is no next position and returns the unchanged position.
pub fn is_last(&self) -> bool
[src]
pub fn is_last(&self) -> bool
Check if we are at the end of the file (the last valid position/the last character of the file).
pub fn prev(&self) -> Option<Position<'t>>
[src]
pub fn prev(&self) -> Option<Position<'t>>
Get the position immediatly following this position or None
if
this is the last position in the file.
pub fn prev_mut(self) -> Result<Self, Self>
[src]
pub fn prev_mut(self) -> Result<Self, Self>
The same as prev()
but in-place.
Fails if there is no prev position and returns the unchanged position.
pub fn line(&self) -> Span<'t>
[src]
pub fn line(&self) -> Span<'t>
Get source code line containing the position.
The returned Span
will include the trailing newline character
of the line.
use asciifile::{AsciiFile, Position, Span}; let file = AsciiFile::new(b"banana\napple\n\nkiwi").unwrap(); let lines = file .iter() .map(|position| { let line = position.line(); (position.chr(), line.as_str().to_string()) }) .collect::<Vec<_>>(); let expected: Vec<(char, String)> = vec![ ('b', "banana\n"), ('a', "banana\n"), ('n', "banana\n"), ('a', "banana\n"), ('n', "banana\n"), ('a', "banana\n"), ('\n', "banana\n"), ('a', "apple\n"), ('p', "apple\n"), ('p', "apple\n"), ('l', "apple\n"), ('e', "apple\n"), ('\n', "apple\n"), ('\n', "\n"), ('k', "kiwi"), ('i', "kiwi"), ('w', "kiwi"), ('i', "kiwi"), ] .into_iter() .map(|(c, s)| (c, s.to_string())) .collect(); assert_eq!(expected, lines);
Windows style line endings are not considered. This means '\r'
will be evaluated as a normal character without any special meaning.
ⓘImportant traits for PositionIterator<'t>pub fn iter(&self) -> PositionIterator<'t>
[src]
pub fn iter(&self) -> PositionIterator<'t>
ⓘImportant traits for ReversePositionIterator<'t>pub fn reverse_iter(&self) -> ReversePositionIterator<'t>
[src]
pub fn reverse_iter(&self) -> ReversePositionIterator<'t>
Trait Implementations
impl<'_> Ord for Position<'_>
[src]
impl<'_> Ord for Position<'_>
fn cmp(&self, other: &Position) -> Ordering
[src]
fn cmp(&self, other: &Position) -> Ordering
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl<'_> PartialEq<Position<'_>> for Position<'_>
[src]
impl<'_> PartialEq<Position<'_>> for Position<'_>
fn eq(&self, rhs: &Position) -> bool
[src]
fn eq(&self, rhs: &Position) -> bool
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'t> Clone for Position<'t>
[src]
impl<'t> Clone for Position<'t>
fn clone(&self) -> Position<'t>
[src]
fn clone(&self) -> Position<'t>
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'t> Copy for Position<'t>
[src]
impl<'t> Copy for Position<'t>
impl<'_> Eq for Position<'_>
[src]
impl<'_> Eq for Position<'_>
impl<'_> PartialOrd<Position<'_>> for Position<'_>
[src]
impl<'_> PartialOrd<Position<'_>> for Position<'_>
fn partial_cmp(&self, other: &Position) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Position) -> Option<Ordering>
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<'_> Display for Position<'_>
[src]
impl<'_> Display for Position<'_>
impl<'_> Debug for Position<'_>
[src]
impl<'_> Debug for Position<'_>
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
impl<T> ToString for T where
T: Display + ?Sized,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId