Struct marked_yaml::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

source

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();
source

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));
source

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));
source

pub fn start(&self) -> Option<&Marker>

The start of the span

assert_eq!(span.start(), Some(&Marker::new(0, 1, 1)));
source

pub fn end(&self) -> Option<&Marker>

The end of the span

assert_eq!(span.end(), Some(&Marker::new(10, 2, 1)));
source

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)));
source

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)));
source

pub fn set_start(&mut self, start: Option<Marker>)

Replace the start of the span

assert_eq!(span.start(), None);
span.set_start(Some(Marker::new(0, 1, 2)));
assert_eq!(span.start(), Some(&Marker::new(0, 1, 2)));
source

pub fn set_end(&mut self, end: Option<Marker>)

Replace the end of the span

assert_eq!(span.end(), None);
span.set_end(Some(Marker::new(0, 1, 2)));
assert_eq!(span.end(), Some(&Marker::new(0, 1, 2)));

Trait Implementations§

source§

impl Clone for Span

source§

fn clone(&self) -> Span

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 Span

source§

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

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

impl PartialEq for Span

source§

fn eq(&self, other: &Span) -> 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 Span

source§

impl Eq for Span

source§

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