Skip to main content

Location

Struct Location 

pub struct Location { /* private fields */ }
Expand description

A (line, column, byte index) location in a YAML document.

line and column are 1-based for any Location produced by parsing or by Location::from_index / Location::new. The single exception is Location::default() (and the Spanned::new constructor it powers), which yields 0/0/0 as a sentinel for “not yet populated by a parser pass.” User code that only ever sees a Location returned from a parser may treat both axes as strictly ≥ 1.

index is always 0-based and counts UTF-8 bytes from the start of the document.

§Examples

use noyalib::Location;
let loc = Location::from_index("a: 1\nb: 2\n", 5);
assert_eq!(loc.line(), 2);
assert_eq!(loc.column(), 1);

Implementations§

§

impl Location

pub fn from_index(input: &str, index: usize) -> Location

Create a new location from a byte index.

§Examples
use noyalib::Location;
let loc = Location::from_index("hello\nworld", 6);
assert_eq!(loc.line(), 2);

pub fn new(line: usize, col: usize, index: usize) -> Location

Create a new location from line, column, and byte index.

§Examples
use noyalib::Location;
let loc = Location::new(1, 1, 0);
assert_eq!(loc.line(), 1);

pub fn index(&self) -> usize

The 0-based byte index.

§Examples
use noyalib::Location;
let loc = Location::from_index("abc", 2);
assert_eq!(loc.index(), 2);

pub fn line(&self) -> usize

The 1-based line number.

Returns 0 only for a Location::default() that has not been populated by a parser pass; any Location produced by Location::from_index, Location::new, or returned from a parser is ≥ 1.

§Examples
use noyalib::Location;
let loc = Location::from_index("a\nb", 2);
assert_eq!(loc.line(), 2);

pub fn column(&self) -> usize

The 1-based column number.

Returns 0 only for a Location::default() that has not been populated by a parser pass; any Location produced by Location::from_index, Location::new, or returned from a parser is ≥ 1.

§Examples
use noyalib::Location;
let loc = Location::from_index("abcd", 3);
assert_eq!(loc.column(), 4);

Trait Implementations§

§

impl Clone for Location

§

fn clone(&self) -> Location

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Location

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Location

§

fn default() -> Location

Returns the “default value” for a type. Read more
§

impl Display for Location

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Hash for Location

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl PartialEq for Location

§

fn eq(&self, other: &Location) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Copy for Location

§

impl Eq for Location

§

impl StructuralPartialEq for Location

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.