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
impl Location
pub fn from_index(input: &str, index: usize) -> 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
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
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
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
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 Copy for Location
impl Eq for Location
impl StructuralPartialEq for Location
Auto Trait Implementations§
impl Freeze for Location
impl RefUnwindSafe for Location
impl Send for Location
impl Sync for Location
impl Unpin for Location
impl UnsafeUnpin for Location
impl UnwindSafe for Location
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.