[][src]Struct tweep::Position

pub struct Position {
    pub line: usize,
    pub column: usize,
    pub kind: PositionKind,
}

One-indexed, line and column numbers to be used within a Context

Examples

let c = Position::abs(1, 3);
assert_eq!((c.line, c.column), (1, 3));

Fields

line: usize

The one-indexed line number

column: usize

The one-indexed column number

kind: PositionKind

Kind of position

Implementations

impl Position[src]

pub fn abs(line: usize, column: usize) -> Self[src]

Create a new absolute Position

Examples

let c = Position::abs(2, 3);
assert_eq!((c.line, c.column), (2, 3));

pub fn rel(line: usize, column: usize) -> Self[src]

Create a new relative Position

Examples

let c = Position::rel(2, 3);
assert_eq!((c.line, c.column), (2, 3));

pub fn subposition(&self, line: usize, column: usize) -> Self[src]

Creates another Position using one-indexed line and column numbers to offset from this position

Examples

let c = Position::abs(2, 3);
// Since these are 1-indexed, this should be the same as c
let s = c.subposition(1, 1);
assert_eq!(c, s);
let c = Position::abs(2, 3);
// When the line number is one, the sub position column will be offset
// from the source position column
let s = c.subposition(1, 3);
assert_eq!(s, Position::abs(2, 5));
let c = Position::abs(2, 3);
// When the line number is greater than one, the column number will be
// offset from the start of that line
let s = c.subposition(2, 1);
assert_eq!(s, Position::abs(3, 1));

Trait Implementations

impl Clone for Position[src]

impl Copy for Position[src]

impl Debug for Position[src]

impl Display for Position[src]

impl Eq for Position[src]

impl PartialEq<Position> for Position[src]

impl StructuralEq for Position[src]

impl StructuralPartialEq for Position[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.