[][src]Struct sise::AtomReadUtil

pub struct AtomReadUtil<R: Reader> { /* fields omitted */ }

Utility to read atom nodes.

Methods

impl<R: Reader> AtomReadUtil<R>[src]

pub fn new(pos: R::Pos, atom: R::String) -> Self[src]

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

Returns a reference to the atom position stored in this utility.

pub fn atom(&self) -> &R::String[src]

Returns a reference to the atom value stored in this utility.

pub fn into_atom(self) -> R::String[src]

Consumes self and returns the stored atom value.

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

Consumes self and returns the stored position.

pub fn into_pos_atom(self) -> (R::Pos, R::String)[src]

Consumes self and returns the stored atom position and value.

pub fn decode<T, F>(
    self,
    f: F,
    value_type: &str
) -> Result<T, ReadUtilError<R::Error, R::Pos>> where
    F: FnOnce(&str) -> Option<T>, 
[src]

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

let src_data = b"example";
let mut parser = sise::Parser::new(src_data);
let node_read_util = sise::NodeReadUtil::new(&mut parser).unwrap();
let atom_read_util = node_read_util.expect_atom().unwrap();
let decoded = atom_read_util.decode(|atom| Some(atom.len()), "decode_as_length").unwrap();
assert_eq!(decoded, 7);

Auto Trait Implementations

impl<R> Send for AtomReadUtil<R> where
    <R as Reader>::Pos: Send,
    <R as Reader>::String: Send

impl<R> Sync for AtomReadUtil<R> where
    <R as Reader>::Pos: Sync,
    <R as Reader>::String: Sync

impl<R> Unpin for AtomReadUtil<R> where
    <R as Reader>::Pos: Unpin,
    <R as Reader>::String: Unpin

impl<R> UnwindSafe for AtomReadUtil<R> where
    <R as Reader>::Pos: UnwindSafe,
    <R as Reader>::String: UnwindSafe

impl<R> RefUnwindSafe for AtomReadUtil<R> where
    <R as Reader>::Pos: RefUnwindSafe,
    <R as Reader>::String: RefUnwindSafe

Blanket Implementations

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

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

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

type Error = !

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> Borrow<T> for T where
    T: ?Sized
[src]

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

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