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
impl Datum
sourcepub fn list_iter(&self) -> Option<ListIter<'_>>
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);
sourcepub fn vector_iter(&self) -> Option<VectorIter<'_>>
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.