[][src]Struct lexpr::Datum

pub struct Datum { /* fields omitted */ }

Combines an S-expression value with location information.

A Datum keeps, along with a plain Value, information about the text location the value was parsed from. For compound values, such as lists and vectors, that includes information for all contained values, recursively.

A Datum can be obtained by using the next_datum and expect_datum methods on Parser, or via the iterator obtained with datum_iter.

Implementations

impl Datum[src]

pub fn value(&self) -> &Value[src]

Returns a reference to the contained value.

pub fn span(&self) -> Span[src]

Returns the span for the compelete value.

pub fn as_ref(&self) -> Ref<'_>[src]

Returns a reference to the datum.

pub fn list_iter(&self) -> Option<ListIter<'_>>[src]

Returns an iterator over the elements of a list.

If the value contained in the datum is not either a cons cell or Null, None is returned.

Note that the returned iterator has special behavior for improper lists, yielding the element after the dot after returning None the first time.

use lexpr::sexp;

let datum = lexpr::datum::from_str("(1 2 . 3)").unwrap();
let mut iter = datum.list_iter().unwrap();
let one = iter.next().unwrap();
assert_eq!(one.value(), &sexp!(1));
let two = iter.next().unwrap();
assert_eq!(two.value(), &sexp!(2));
assert_eq!(iter.next(), None);
let three = iter.next().unwrap();
assert_eq!(three.value(), &sexp!(3));
assert_eq!(iter.next(), None);

pub fn vector_iter(&self) -> Option<VectorIter<'_>>[src]

Returns an iterator over the elements of a vector.

If the value contained in the datum is not a vector, None is returned.

Trait Implementations

impl Clone for Datum[src]

impl Debug for Datum[src]

impl From<Datum> for Value[src]

impl<'a> From<Ref<'a>> for Datum[src]

pub fn from(r: Ref<'a>) -> Self[src]

Turns a reference into an owned Datum, by cloning the referenced value and location information.

impl PartialEq<Datum> for Datum[src]

impl StructuralPartialEq for Datum[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.