Struct sise::AtomNodeReadUtil
source · pub struct AtomNodeReadUtil<'a> { /* private fields */ }
Expand description
Utility to read atom nodes.
Implementations§
source§impl<'a> AtomNodeReadUtil<'a>
impl<'a> AtomNodeReadUtil<'a>
pub fn new(atom: &'a str, pos: Option<Pos>) -> Self
sourcepub fn decode<T, F>(&self, f: F, value_type: &str) -> Result<T, ReadUtilError>where
F: FnOnce(&str) -> Option<T>,
pub fn decode<T, F>(&self, f: F, value_type: &str) -> Result<T, ReadUtilError>where
F: FnOnce(&str) -> Option<T>,
Decodes the atom using an user-provided function.
The function shall return None
if the decodification
fails. In such case, ReadError::InvalidValue
will be
returned, with the value of value_type
.
Example
use sise::sise_expr;
let node = sise_expr!("example");
let node_read_util = sise::NodeReadUtil::new(&node, None);
let atom_read_util = node_read_util.as_atom().unwrap();
let decoded = atom_read_util.decode(|atom| Some(atom.len()), "decode_as_atom").unwrap();
assert_eq!(decoded, 7);
Trait Implementations§
source§impl<'a> Clone for AtomNodeReadUtil<'a>
impl<'a> Clone for AtomNodeReadUtil<'a>
source§fn clone(&self) -> AtomNodeReadUtil<'a>
fn clone(&self) -> AtomNodeReadUtil<'a>
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