Struct marked_yaml::types::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
impl Marker
sourcepub fn new(source: usize, line: usize, column: usize) -> Self
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);
sourcepub fn source(&self) -> usize
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);
sourcepub fn line(&self) -> usize
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);
sourcepub fn column(&self) -> usize
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);
sourcepub fn render<D, F>(self, renderfn: F) -> RenderedMarker<D>
pub fn render<D, F>(self, renderfn: F) -> RenderedMarker<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")
sourcepub fn set_source(&mut self, source: usize)
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);
sourcepub fn set_line(&mut self, line: usize)
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);
sourcepub fn set_column(&mut self, column: usize)
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 PartialEq for Marker
impl PartialEq for Marker
impl Copy for Marker
impl Eq for Marker
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> 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: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)