[−][src]Struct sise::AtomReadUtil
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]
self,
f: F,
value_type: &str
) -> Result<T, ReadUtilError<R::Error, R::Pos>> 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
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,
<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,
<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,
<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,
<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,
<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]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,