Even more style
This commit is contained in:
@@ -29,8 +29,8 @@ impl<'a, 'view> View<'a, 'view> for Rlp<'a> where 'a: 'view {
|
||||
}
|
||||
}
|
||||
|
||||
fn raw(&'view self) -> &'a [u8] {
|
||||
self.rlp.raw()
|
||||
fn as_raw(&'view self) -> &'a [u8] {
|
||||
self.rlp.as_raw()
|
||||
}
|
||||
|
||||
fn prototype(&self) -> Self::Prototype {
|
||||
|
||||
@@ -32,11 +32,11 @@ pub trait View<'a, 'view>: Sized {
|
||||
/// 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);
|
||||
/// let dog = rlp.at(1).raw();
|
||||
/// let dog = rlp.at(1).as_raw();
|
||||
/// assert_eq!(dog, &[0x83, b'd', b'o', b'g']);
|
||||
/// }
|
||||
/// ```
|
||||
fn raw(&'view self) -> &'a [u8];
|
||||
fn as_raw(&'view self) -> &'a [u8];
|
||||
|
||||
/// Get the prototype of the RLP.
|
||||
fn prototype(&self) -> Self::Prototype;
|
||||
|
||||
@@ -19,19 +19,19 @@ fn rlp_at() {
|
||||
|
||||
let cat = rlp.at(0).unwrap();
|
||||
assert!(cat.is_data());
|
||||
assert_eq!(cat.raw(), &[0x83, b'c', b'a', b't']);
|
||||
assert_eq!(cat.as_raw(), &[0x83, b'c', b'a', b't']);
|
||||
//assert_eq!(String::decode_untrusted(&cat).unwrap(), "cat".to_string());
|
||||
assert_eq!(cat.as_val::<String>().unwrap(), "cat".to_string());
|
||||
|
||||
let dog = rlp.at(1).unwrap();
|
||||
assert!(dog.is_data());
|
||||
assert_eq!(dog.raw(), &[0x83, b'd', b'o', b'g']);
|
||||
assert_eq!(dog.as_raw(), &[0x83, b'd', b'o', b'g']);
|
||||
//assert_eq!(String::decode_untrusted(&dog).unwrap(), "dog".to_string());
|
||||
assert_eq!(dog.as_val::<String>().unwrap(), "dog".to_string());
|
||||
|
||||
let cat_again = rlp.at(0).unwrap();
|
||||
assert!(cat_again.is_data());
|
||||
assert_eq!(cat_again.raw(), &[0x83, b'c', b'a', b't']);
|
||||
assert_eq!(cat_again.as_raw(), &[0x83, b'c', b'a', b't']);
|
||||
//assert_eq!(String::decode_untrusted(&cat_again).unwrap(), "cat".to_string());
|
||||
assert_eq!(cat_again.as_val::<String>().unwrap(), "cat".to_string());
|
||||
}
|
||||
@@ -61,18 +61,18 @@ fn rlp_iter() {
|
||||
|
||||
let cat = iter.next().unwrap();
|
||||
assert!(cat.is_data());
|
||||
assert_eq!(cat.raw(), &[0x83, b'c', b'a', b't']);
|
||||
assert_eq!(cat.as_raw(), &[0x83, b'c', b'a', b't']);
|
||||
|
||||
let dog = iter.next().unwrap();
|
||||
assert!(dog.is_data());
|
||||
assert_eq!(dog.raw(), &[0x83, b'd', b'o', b'g']);
|
||||
assert_eq!(dog.as_raw(), &[0x83, b'd', b'o', b'g']);
|
||||
|
||||
let none = iter.next();
|
||||
assert!(none.is_none());
|
||||
|
||||
let cat_again = rlp.at(0).unwrap();
|
||||
assert!(cat_again.is_data());
|
||||
assert_eq!(cat_again.raw(), &[0x83, b'c', b'a', b't']);
|
||||
assert_eq!(cat_again.as_raw(), &[0x83, b'c', b'a', b't']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ impl<'a, 'view> View<'a, 'view> for UntrustedRlp<'a> where 'a: 'view {
|
||||
}
|
||||
}
|
||||
|
||||
fn raw(&'view self) -> &'a [u8] {
|
||||
fn as_raw(&'view self) -> &'a [u8] {
|
||||
self.bytes
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ impl<'a> Decoder for BasicDecoder<'a> {
|
||||
fn read_value<T, F>(&self, f: F) -> Result<T, DecoderError>
|
||||
where F: FnOnce(&[u8]) -> Result<T, DecoderError> {
|
||||
|
||||
let bytes = self.rlp.raw();
|
||||
let bytes = self.rlp.as_raw();
|
||||
|
||||
match bytes.first().map(|&x| x) {
|
||||
// rlp is too short
|
||||
@@ -316,7 +316,7 @@ impl<'a> Decoder for BasicDecoder<'a> {
|
||||
}
|
||||
|
||||
fn as_raw(&self) -> &[u8] {
|
||||
self.rlp.raw()
|
||||
self.rlp.as_raw()
|
||||
}
|
||||
|
||||
fn as_list(&self) -> Result<Vec<Self>, DecoderError> {
|
||||
|
||||
Reference in New Issue
Block a user