Struct serde_lexpr::parse::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 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 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<Datum> for Datum

source§

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

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.