[][src]Struct sise::ListReadUtil

pub struct ListReadUtil<'a, R: Reader> { /* fields omitted */ }

Read util list

Methods

impl<'a, R: Reader> ListReadUtil<'a, R>[src]

pub fn new(beginning_pos: R::Pos, reader: &'a mut R) -> Self[src]

pub fn beginning_pos(&self) -> &R::Pos[src]

Returns a reference to the stored list beginning position.

pub fn into_beginning_pos(self) -> R::Pos[src]

Consumes self and returns the stored list beginning position.

pub fn expect_ending(self) -> Result<R::Pos, ReadUtilError<R::Error, R::Pos>>[src]

Checks if all the nodes in the list have been read. If not, it returns a ReadUtilError::ExpectedListEnding error.

Example

let src_data = b"()";
let mut parser = sise::Parser::new(src_data);
let node_read_util = sise::NodeReadUtil::new(&mut parser).unwrap();
let list_read_util = node_read_util.expect_list().unwrap();
assert!(list_read_util.expect_ending().is_ok());

pub fn try_next_item(&mut self) -> Result<Option<NodeReadUtil<R>>, R::Error>[src]

Reads the next item in the list. If none are left, it returns None.

Example

let src_data = b"(a b c)";
let mut parser = sise::Parser::new(src_data);
let node_read_util = sise::NodeReadUtil::new(&mut parser).unwrap();
let mut list_read_util = node_read_util.expect_list().unwrap();
assert_eq!(list_read_util.try_next_item().unwrap().unwrap().expect_atom().unwrap().into_atom(), "a");
assert_eq!(list_read_util.try_next_item().unwrap().unwrap().expect_atom().unwrap().into_atom(), "b");
assert_eq!(list_read_util.try_next_item().unwrap().unwrap().expect_atom().unwrap().into_atom(), "c");
assert!(list_read_util.try_next_item().unwrap().is_none());

pub fn next_item(
    &mut self
) -> Result<NodeReadUtil<R>, ReadUtilError<R::Error, R::Pos>>
[src]

Reads the next item in the list. If none are left, it returns a ReadUtilError::ExpectedNodeInList.

Example

let src_data = b"(a b c)";
let mut parser = sise::Parser::new(src_data);
let node_read_util = sise::NodeReadUtil::new(&mut parser).unwrap();
let mut list_read_util = node_read_util.expect_list().unwrap();
assert_eq!(list_read_util.next_item().unwrap().expect_atom().unwrap().into_atom(), "a");
assert_eq!(list_read_util.next_item().unwrap().expect_atom().unwrap().into_atom(), "b");
assert_eq!(list_read_util.next_item().unwrap().expect_atom().unwrap().into_atom(), "c");
assert!(list_read_util.next_item().is_err());

pub fn decode_atoms<T, F>(
    self,
    f: F,
    value_type: &str,
    can_be_empty: bool
) -> Result<Vec<T>, ReadUtilError<R::Error, R::Pos>> where
    F: FnMut(&str) -> Option<T>, 
[src]

Gets the remaining items from the list, checks if they are atoms and decodes their value using f, returning a Vec with the result.

Example

let src_data = b"(1 12 123)";
let mut parser = sise::Parser::new(src_data);
let node_read_util = sise::NodeReadUtil::new(&mut parser).unwrap();
let mut list_read_util = node_read_util.expect_list().unwrap();
let decoded = list_read_util.decode_atoms(|atom| Some(atom.len()), "decode_as_length", false).unwrap();
assert_eq!(decoded, [1, 2, 3]);

Auto Trait Implementations

impl<'a, R> Send for ListReadUtil<'a, R> where
    R: Send,
    <R as Reader>::Pos: Send

impl<'a, R> Sync for ListReadUtil<'a, R> where
    R: Sync,
    <R as Reader>::Pos: Sync

Blanket Implementations

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

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

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.

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

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

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