Skip to main content

Span

Struct 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, 0, 1, 1), Marker::new(100, 9, 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, 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, 0, 1, 1), Marker::new(10, 1, 2, 1));
Source

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

The start of the span

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

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

The end of the span

assert_eq!(span.end(), Some(&Marker::new(10, 1, 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, 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, 1, 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, 1, 2)));
assert_eq!(span.start(), Some(&Marker::new(0, 1, 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, 1, 2)));
assert_eq!(span.end(), Some(&Marker::new(0, 1, 1, 2)));

Trait Implementations§

Source§

impl Clone for Span

Source§

fn clone(&self) -> Span

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Span

Source§

impl Debug for Span

Source§

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

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

impl Eq for Span

Source§

impl PartialEq for Span

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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 UnsafeUnpin 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

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

Source§

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.