Struct marked_yaml::Marker

source ·
pub struct Marker { /* private fields */ }
Expand description

A marker for a YAML node

This indicates where a node started or ended.

use marked_yaml::{parse_yaml, Marker};
let node = parse_yaml(100, "{foo: bar}").unwrap();
let map = node.as_mapping().unwrap();
let bar = map.get("foo").unwrap();
// the "bar" string started on line 1, column 7 of source ID 100.
assert_eq!(bar.span().start(), Some(&Marker::new(100, 1, 7)));

Implementations§

source§

impl Marker

source

pub fn new(source: usize, line: usize, column: usize) -> Self

Create a new Marker

This will typically not be used because markers will come from parsing YAML, however it is provided for completeness and in case you need it for your own tests.

let marker = Marker::new(0, 1, 2);
source

pub fn source(&self) -> usize

The source index given for this marker.

When parsing YAML, we record where nodes start (and often finish). This is the source index provided when parsing the YAML. Likely this refers to a vector of PathBuf recording where input came from, but that is entirely up to the user of this library crate.

This is likely most useful to computers, not humans.

assert_eq!(marker.source(), 0);
source

pub fn line(&self) -> usize

The line number on which this marker resides, 1-indexed

When parsing YAML, we record where nodes start (and often finish). This is the line number of where this marker resides. Line numbers start with 1 to make them more useful to humans.

assert_eq!(marker.line(), 1);
source

pub fn column(&self) -> usize

The column number at which this marker resides, 1-indexed

When parsing YAML, we record where nodes start (and often finish). This is the column number of where this marker resides. Column numbers start with 1 to make them more useful to humans.

assert_eq!(marker.column(), 2);
source

pub fn render<D, F>(self, renderfn: F) -> RenderedMarker<D>
where D: Display, F: FnOnce(usize) -> D,

Render this marker

Markers have a source identifier, typically as passed to parse_yaml() but have no way in and of themselves to turn that into a useful name. This function allows you to create a rendered marker which knows how to show the source name.

let rendered = marker.render(|_| "name");
assert_eq!(format!("{}", rendered), "name:1:2")
source

pub fn set_source(&mut self, source: usize)

Set the source index for this marker

assert_ne!(marker.source(), 1);
marker.set_source(1);
assert_eq!(marker.source(), 1);
source

pub fn set_line(&mut self, line: usize)

Set the line number for this marker

assert_ne!(marker.line(), 1);
marker.set_line(1);
assert_eq!(marker.line(), 1);
source

pub fn set_column(&mut self, column: usize)

Set the column number for this marker

assert_ne!(marker.column(), 1);
marker.set_column(1);
assert_eq!(marker.column(), 1);

Trait Implementations§

source§

impl Clone for Marker

source§

fn clone(&self) -> Marker

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Marker

source§

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

Formats the value using the given formatter. Read more
source§

impl Display for Marker

source§

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

Formats the value using the given formatter. Read more
source§

impl PartialEq for Marker

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

impl Copy for Marker

source§

impl Eq for Marker

source§

impl StructuralPartialEq for Marker

Auto Trait Implementations§

§

impl Freeze for Marker

§

impl RefUnwindSafe for Marker

§

impl Send for Marker

§

impl Sync for Marker

§

impl Unpin for Marker

§

impl UnwindSafe for Marker

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: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

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

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

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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

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

source§

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

Checks if this value is equivalent to the given key. Read more
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,

§

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§

default 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>,

§

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>,

§

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.