diff --git a/src/rlp/rlp.rs b/src/rlp/rlp.rs index ce43c10a5..ac830cc9c 100644 --- a/src/rlp/rlp.rs +++ b/src/rlp/rlp.rs @@ -84,16 +84,24 @@ impl<'a, 'view> View<'a, 'view> for Rlp<'a> where 'a: 'view { fn as_val(&self) -> Result where T: Decodable { self.rlp.as_val() } + + fn val_at(&self, index: usize) -> Result where T: Decodable { + self.at(index).rlp.as_val() + } } impl <'a, 'view> Rlp<'a> where 'a: 'view { - fn reader_as_val(r: &R) -> T where R: View<'a, 'view>, T: Decodable { + fn view_as_val(r: &R) -> T where R: View<'a, 'view>, T: Decodable { let res: Result = r.as_val(); res.unwrap_or_else(|_| panic!()) } pub fn as_val(&self) -> T where T: Decodable { - Self::reader_as_val(self) + Self::view_as_val(self) + } + + pub fn val_at(&self, index: usize) -> T where T: Decodable { + Self::view_as_val(&self.at(index)) } } diff --git a/src/rlp/traits.rs b/src/rlp/traits.rs index 966078b08..1127ca3db 100644 --- a/src/rlp/traits.rs +++ b/src/rlp/traits.rs @@ -179,6 +179,8 @@ pub trait View<'a, 'view>: Sized { fn iter(&'view self) -> Self::Iter; fn as_val(&self) -> Result where T: Decodable; + + fn val_at(&self, index: usize) -> Result where T: Decodable; } pub trait Encoder { diff --git a/src/rlp/untrusted_rlp.rs b/src/rlp/untrusted_rlp.rs index 19dd5e99c..eae253eca 100644 --- a/src/rlp/untrusted_rlp.rs +++ b/src/rlp/untrusted_rlp.rs @@ -176,6 +176,10 @@ impl<'a, 'view> View<'a, 'view> for UntrustedRlp<'a> where 'a: 'view { // optimize, so it doesn't use clone (although This clone is cheap) T::decode(&BasicDecoder::new(self.clone())) } + + fn val_at(&self, index: usize) -> Result where T: Decodable { + self.at(index).unwrap().as_val() + } } impl<'a> UntrustedRlp<'a> {