Datum

Struct Datum 

Source
pub struct Datum { /* private fields */ }
Expand description

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§

Source§

impl Datum

Source

pub fn value(&self) -> &Value

Returns a reference to the contained value.

Source

pub fn span(&self) -> Span

Returns the span for the compelete value.

Source

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

Returns a reference to the datum.

Source

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

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

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

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§

Source§

impl Clone for Datum

Source§

fn clone(&self) -> Datum

Returns a duplicate 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 Datum

Source§

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

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

impl From<Datum> for Value

Source§

fn from(datum: Datum) -> Value

Converts to this type from the input type.
Source§

impl<'a> From<Ref<'a>> for Datum

Source§

fn from(r: Ref<'a>) -> Datum

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

Source§

impl PartialEq for Datum

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Datum

Auto Trait Implementations§

§

impl Freeze for Datum

§

impl RefUnwindSafe for Datum

§

impl Send for Datum

§

impl Sync for Datum

§

impl Unpin for Datum

§

impl UnwindSafe for Datum

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