rlp items functions

This commit is contained in:
debris 2015-11-30 12:41:11 +01:00
parent 80f1e527dc
commit b6dc3e464d

View File

@ -152,6 +152,24 @@ impl<'a> Rlp<'a> {
self.rlp.data()
}
/// Returns number of rlp items.
///
/// ```rust
/// extern crate ethcore_util as util;
/// use util::rlp::*;
///
/// fn main () {
/// let data = vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'];
/// let rlp = Rlp::new(&data);
/// assert_eq!(rlp.items(), 2);
/// let view = rlp.at(1);
/// assert_eq!(view.items(), 0);
/// }
/// ```
pub fn items(&self) -> usize {
self.rlp.items()
}
/// Get view onto rlp-slice at index.
///
/// Caches offset to given index, so access to successive
@ -297,6 +315,27 @@ impl<'a> UntrustedRlp<'a> {
self.bytes
}
/// Returns number of rlp items.
///
/// ```rust
/// extern crate ethcore_util as util;
/// use util::rlp::*;
///
/// fn main () {
/// let data = vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'];
/// let rlp = UntrustedRlp::new(&data);
/// assert_eq!(rlp.items(), 2);
/// let view = rlp.at(1).unwrap();
/// assert_eq!(view.items(), 0);
/// }
/// ```
pub fn items(&self) -> usize {
match self.is_list() {
true => self.iter().count(),
false => 0
}
}
/// Get view onto rlp-slice at index
///
/// Caches offset to given index, so access to successive