Struct marked_yaml::types::Span
source · pub struct Span { /* private fields */ }
Expand description
The span for a YAML marked node
use marked_yaml::{parse_yaml, Marker, Span};
let node = parse_yaml(100, "{foo: bar}").unwrap();
let map = node.as_mapping().unwrap();
assert_eq!(map.span(), &Span::new_with_marks(Marker::new(100, 1, 1), Marker::new(100, 1, 10)));
Implementations§
source§impl Span
impl Span
sourcepub fn new_blank() -> Self
pub fn new_blank() -> Self
Create a span with no marker information
Sometimes we simply do not know where information came from (for example if it was created by software) and in that case we can create a blank span.
let blank = Span::new_blank();
sourcepub fn new_start(start: Marker) -> Self
pub fn new_start(start: Marker) -> Self
Create a span with only start information
Sometimes when creating a span we know where it started but not where it ends. This might be during parsing, or for some other reason.
let span = Span::new_start(Marker::new(0, 1, 2));
sourcepub fn new_with_marks(start: Marker, end: Marker) -> Self
pub fn new_with_marks(start: Marker, end: Marker) -> Self
Create a span with both start and end markers
When we know both the start and end of a node, we can create a span which has all that knowledge.
let span = Span::new_with_marks(Marker::new(0, 1, 1), Marker::new(10, 2, 1));
sourcepub fn start(&self) -> Option<&Marker>
pub fn start(&self) -> Option<&Marker>
The start of the span
assert_eq!(span.start(), Some(&Marker::new(0, 1, 1)));
sourcepub fn end(&self) -> Option<&Marker>
pub fn end(&self) -> Option<&Marker>
The end of the span
assert_eq!(span.end(), Some(&Marker::new(10, 2, 1)));
sourcepub fn start_mut(&mut self) -> Option<&mut Marker>
pub fn start_mut(&mut self) -> Option<&mut Marker>
The start of the span, mutably
span.start_mut().unwrap().set_line(5);
assert_eq!(span.start(), Some(&Marker::new(0, 5, 1)));
sourcepub fn end_mut(&mut self) -> Option<&mut Marker>
pub fn end_mut(&mut self) -> Option<&mut Marker>
The end of the span, mutably
span.end_mut().unwrap().set_line(5);
assert_eq!(span.end(), Some(&Marker::new(10, 5, 1)));
Trait Implementations§
source§impl PartialEq for Span
impl PartialEq for Span
impl Copy for Span
impl Eq for Span
impl StructuralPartialEq for Span
Auto Trait Implementations§
impl Freeze for Span
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnwindSafe for Span
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
Mutably borrows from an owned value. Read more
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)
🔬This is a nightly-only experimental API. (
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)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)