Struct Position
struct Position<'i> { ... }
A cursor position in a &str which provides useful methods to manually parse that string.
Implementations
impl<'i> Position<'i>
fn new(input: &str, pos: usize) -> Option<Position<'_>>Attempts to create a new
Positionat the given position. If the specified position is an invalid index, or the specified position is not a valid UTF8 boundary, then None is returned.Examples
# use Position; let cheart = '💖'; let heart = "💖"; assert_eq!; assert_ne!;fn from_start(input: &'i str) -> Position<'i>Creates a
Positionat the start of a&str.Examples
# use Position; let start = from_start; assert_eq!;fn pos(self: &Self) -> usizeReturns the byte position of this
Positionas ausize.Examples
# use Position; let input = "ab"; let mut start = from_start; assert_eq!;fn span(self: &Self, other: &Position<'i>) -> Span<'i>Creates a
Spanfrom twoPositions.Panics
Panics if the positions come from different inputs.
Examples
# use Position; let input = "ab"; let start = from_start; let span = start.span; assert_eq!; assert_eq!;fn line_col(self: &Self) -> (usize, usize)Returns the line and column number of this
Position.This is an O(n) operation, where n is the number of chars in the input. You better use
pair.line_col()instead.Examples
# use pest; # # let input = "\na"; let mut state: = new; let mut result = state.match_string; assert!; assert_eq!;fn line_of(self: &Self) -> &'i strReturns the entire line of the input that contains this
Position.Examples
# use pest; # # let input = "\na"; let mut state: = new; let mut result = state.match_string; assert!; assert_eq!;
impl<'i> Clone for Position<'i>
fn clone(self: &Self) -> Position<'i>
impl<'i> Copy for Position<'i>
impl<'i> Debug for Position<'i>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<'i> Eq for Position<'i>
impl<'i> Freeze for Position<'i>
impl<'i> Hash for Position<'i>
fn hash<H: Hasher>(self: &Self, state: &mut H)
impl<'i> Ord for Position<'i>
fn cmp(self: &Self, other: &Position<'i>) -> Ordering
impl<'i> PartialEq for Position<'i>
fn eq(self: &Self, other: &Position<'i>) -> bool
impl<'i> PartialOrd for Position<'i>
fn partial_cmp(self: &Self, other: &Position<'i>) -> Option<Ordering>
impl<'i> RefUnwindSafe for Position<'i>
impl<'i> Send for Position<'i>
impl<'i> Sync for Position<'i>
impl<'i> Unpin for Position<'i>
impl<'i> UnsafeUnpin for Position<'i>
impl<'i> UnwindSafe for Position<'i>
impl<T> Any for Position<'i>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Position<'i>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Position<'i>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Position<'i>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Position<'i>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> RuleType for Position<'i>
impl<T> ToOwned for Position<'i>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for Position<'i>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Position<'i>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Position<'i>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>