diff --git a/src/overlaydb.rs b/src/overlaydb.rs index b6f2b3eb2..24e4ea8da 100644 --- a/src/overlaydb.rs +++ b/src/overlaydb.rs @@ -130,7 +130,7 @@ impl OverlayDB { let mut s = RlpStream::new_list(2); s.append(&payload.1); s.append(&payload.0); - self.backing.put(&key.bytes(), &s.out().unwrap()).expect("Low-level database error. Some issue with your hard disk?"); + self.backing.put(&key.bytes(), &s.out()).expect("Low-level database error. Some issue with your hard disk?"); } } diff --git a/src/rlp.rs b/src/rlp.rs index f76f1f5b9..737f7f416 100644 --- a/src/rlp.rs +++ b/src/rlp.rs @@ -550,7 +550,7 @@ impl RlpStream { /// fn main () { /// let mut stream = RlpStream::new_list(2); /// stream.append(&"cat").append(&"dog"); - /// let out = stream.out().unwrap(); + /// let out = stream.out(); /// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); /// } /// ``` @@ -575,7 +575,7 @@ impl RlpStream { /// let mut stream = RlpStream::new_list(2); /// stream.append_list(2).append(&"cat").append(&"dog"); /// stream.append(&""); - /// let out = stream.out().unwrap(); + /// let out = stream.out(); /// assert_eq!(out, vec![0xca, 0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g', 0x80]); /// } /// ``` @@ -604,7 +604,7 @@ impl RlpStream { /// fn main () { /// let mut stream = RlpStream::new_list(2); /// stream.append_null().append_null(); - /// let out = stream.out().unwrap(); + /// let out = stream.out(); /// assert_eq!(out, vec![0xc2, 0x80, 0x80]); /// } /// ``` @@ -643,7 +643,7 @@ impl RlpStream { /// assert_eq!(stream.is_finished(), false); /// stream.append(&"dog"); /// assert_eq!(stream.is_finished(), true); - /// let out = stream.out().unwrap(); + /// let out = stream.out(); /// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); /// } pub fn is_finished(&self) -> bool { @@ -652,11 +652,11 @@ impl RlpStream { /// Streams out encoded bytes. /// - /// Returns an error if stream is not finished. - pub fn out(self) -> Result, EncoderError> { + /// panic! if stream is not finished + pub fn out(self) -> Vec { match self.is_finished() { - true => Ok(self.encoder.out()), - false => Err(EncoderError::StreamIsUnfinished), + true => self.encoder.out(), + false => panic!() } } @@ -701,23 +701,6 @@ pub fn encode(object: &E) -> Vec where E: Encodable encoder.out() } -#[derive(Debug)] -pub enum EncoderError { - StreamIsUnfinished, -} - -impl StdError for EncoderError { - fn description(&self) -> &str { - "encoder error" - } -} - -impl fmt::Display for EncoderError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(&self, f) - } -} - pub trait Encodable { fn encode(&self, encoder: &mut E) -> () where E: Encoder; } @@ -1035,7 +1018,7 @@ mod tests { fn rlp_stream() { let mut stream = RlpStream::new_list(2); stream.append(&"cat").append(&"dog"); - let out = stream.out().unwrap(); + let out = stream.out(); assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); } @@ -1046,7 +1029,7 @@ mod tests { stream.append_list(0); stream.append_list(1).append_list(0); stream.append_list(2).append_list(0).append_list(1).append_list(0); - let out = stream.out().unwrap(); + let out = stream.out(); assert_eq!(out, vec![0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]); } @@ -1057,7 +1040,7 @@ mod tests { for _ in 0..17 { stream.append(&""); } - let out = stream.out().unwrap(); + let out = stream.out(); assert_eq!(out, vec![0xd1, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80]); @@ -1073,9 +1056,9 @@ mod tests { stream.append(&"aaa"); res.extend(vec![0x83, b'a', b'a', b'a']); } - let out = stream.out().unwrap(); + let out = stream.out(); assert_eq!(out, res); - } + }; struct DTestPair(T, Vec) where T: rlp::Decodable + fmt::Debug + cmp::Eq; diff --git a/src/triehash.rs b/src/triehash.rs index abc13a39e..aaeef5f65 100644 --- a/src/triehash.rs +++ b/src/triehash.rs @@ -177,7 +177,7 @@ pub fn hash256(vec: &[NibblePair]) -> H256 { _ => { let mut stream = RlpStream::new(); hash256rlp(&vec, 0, &mut stream); - stream.out().unwrap() + stream.out() } }; @@ -251,7 +251,7 @@ fn hash256rlp(vec: &[NibblePair], pre_len: usize, stream: &mut RlpStream) { fn hash256aux(vec: &[NibblePair], pre_len: usize, stream: &mut RlpStream) { let mut s = RlpStream::new(); hash256rlp(vec, pre_len, &mut s); - let out = s.out().unwrap(); + let out = s.out(); match out.len() { 0...31 => stream.append_raw(&out, 1), _ => stream.append(&out.sha3())