Struct sise::ListNodeReadUtil
source · pub struct ListNodeReadUtil<'a, 'b> { /* private fields */ }
Expand description
Utility to read list nodes.
Implementations§
source§impl<'a, 'b> ListNodeReadUtil<'a, 'b>
impl<'a, 'b> ListNodeReadUtil<'a, 'b>
pub fn new(list: &'a [Node], pos_tree: Option<&'b PosTree>) -> Self
sourcepub fn pos_tree(&self) -> Option<&'b PosTree>
pub fn pos_tree(&self) -> Option<&'b PosTree>
Returns the position tree of the list in this utility.
sourcepub fn expect_end(&self) -> Result<(), ReadUtilError>
pub fn expect_end(&self) -> Result<(), ReadUtilError>
Checks if all the nodes in the list have been read.
If not, it returns a ReadError::ExpectedListEnd
error.
Example
use sise::sise_expr;
let node = sise_expr!([]);
let node_read_util = sise::NodeReadUtil::new(&node, None);
let list_read_util = node_read_util.as_list().unwrap();
assert!(list_read_util.expect_end().is_ok());
sourcepub fn try_next_item(&mut self) -> Option<NodeReadUtil<'a, 'b>>
pub fn try_next_item(&mut self) -> Option<NodeReadUtil<'a, 'b>>
Reads the next item in the list. If none are left, it
returns None
.
Example
use sise::sise_expr;
let node = sise_expr!(["a", "b"]);
let node_read_util = sise::NodeReadUtil::new(&node, None);
let mut list_read_util = node_read_util.as_list().unwrap();
assert_eq!(list_read_util.try_next_item().unwrap().node(), "a");
assert_eq!(list_read_util.try_next_item().unwrap().node(), "b");
assert!(list_read_util.try_next_item().is_none());
sourcepub fn next_item(&mut self) -> Result<NodeReadUtil<'a, 'b>, ReadUtilError>
pub fn next_item(&mut self) -> Result<NodeReadUtil<'a, 'b>, ReadUtilError>
Reads the next item in the list. If none are left, it
returns a ReadError::ExpectedNodeInList
error.
Example
use sise::sise_expr;
let node = sise_expr!(["a", "b"]);
let node_read_util = sise::NodeReadUtil::new(&node, None);
let mut list_read_util = node_read_util.as_list().unwrap();
assert_eq!(list_read_util.next_item().unwrap().node(), "a");
assert_eq!(list_read_util.next_item().unwrap().node(), "b");
sourcepub fn decode_atoms<T, F>(
self,
f: F,
value_type: &str,
can_be_empty: bool
) -> Result<Vec<T>, ReadUtilError>where
F: FnMut(&str) -> Option<T>,
pub fn decode_atoms<T, F>(
self,
f: F,
value_type: &str,
can_be_empty: bool
) -> Result<Vec<T>, ReadUtilError>where
F: FnMut(&str) -> Option<T>,
Gets the remaining items from the list, checks if they
are atoms and decodes their value using f
.
Example
use sise::sise_expr;
let node = sise_expr!(["1", "12", "123"]);
let node_read_util = sise::NodeReadUtil::new(&node, None);
let list_read_util = node_read_util.as_list().unwrap();
let decoded = list_read_util.decode_atoms(|atom| Some(atom.len()), "decode_as_atom", false).unwrap();
assert_eq!(decoded, [1, 2, 3]);
Trait Implementations§
source§impl<'a, 'b> Clone for ListNodeReadUtil<'a, 'b>
impl<'a, 'b> Clone for ListNodeReadUtil<'a, 'b>
source§fn clone(&self) -> ListNodeReadUtil<'a, 'b>
fn clone(&self) -> ListNodeReadUtil<'a, 'b>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more