Rlp

Struct Rlp 

Source
pub struct Rlp<'a> { /* private fields */ }
Expand description

Data-oriented view onto trusted rlp-slice.

Unlikely to UntrustedRlp doesn’t bother you with error handling. It assumes that you know what you are doing.

Implementations§

Source§

impl<'a, 'view> Rlp<'a>
where 'a: 'view,

Source

pub fn new(bytes: &'a [u8]) -> Rlp<'a>

Create a new instance of Rlp

Source

pub fn as_raw(&'view self) -> &'a [u8]

The raw data of the RLP as slice.

extern crate rlp;
use 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);
	let dog = rlp.at(1).as_raw();
	assert_eq!(dog, &[0x83, b'd', b'o', b'g']);
}
Source

pub fn prototype(&self) -> Prototype

Get the prototype of the RLP.

Source

pub fn payload_info(&self) -> PayloadInfo

Get payload info.

Source

pub fn data(&'view self) -> &'a [u8]

Get underlieing data.

Source

pub fn item_count(&self) -> usize

Returns number of RLP items.

extern crate rlp;
use 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.item_count(), 2);
	let view = rlp.at(1);
	assert_eq!(view.item_count(), 0);
}
Source

pub fn size(&self) -> usize

Returns the number of bytes in the data, or zero if it isn’t data.

extern crate rlp;
use 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.size(), 0);
	let view = rlp.at(1);
	assert_eq!(view.size(), 3);
}
Source

pub fn at(&'view self, index: usize) -> Rlp<'a>

Get view onto RLP-slice at index.

Caches offset to given index, so access to successive slices is faster.

extern crate rlp;
use 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);
	let dog: String = rlp.at(1).as_val();
	assert_eq!(dog, "dog".to_string());
}
Source

pub fn is_null(&self) -> bool

No value

extern crate rlp;
use rlp::*;

fn main () {
	let data = vec![];
	let rlp = Rlp::new(&data);
	assert!(rlp.is_null());
}
Source

pub fn is_empty(&self) -> bool

Contains a zero-length string or zero-length list.

extern crate rlp;
use rlp::*;

fn main () {
	let data = vec![0xc0];
	let rlp = Rlp::new(&data);
	assert!(rlp.is_empty());
}
Source

pub fn is_list(&self) -> bool

List value

extern crate rlp;
use 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!(rlp.is_list());
}
Source

pub fn is_data(&self) -> bool

String value

extern crate rlp;
use 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!(rlp.at(1).is_data());
}
Source

pub fn is_int(&self) -> bool

Int value

extern crate rlp;
use rlp::*;

fn main () {
	let data = vec![0xc1, 0x10];
	let rlp = Rlp::new(&data);
	assert_eq!(rlp.is_int(), false);
	assert_eq!(rlp.at(0).is_int(), true);
}
Source

pub fn iter(&'view self) -> RlpIterator<'a, 'view>

Get iterator over rlp-slices

extern crate rlp;
use 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);
	let strings: Vec<String> = rlp.iter().map(| i | i.as_val()).collect();
}
Source

pub fn as_val<T>(&self) -> T
where T: Decodable,

Decode data into an object

Source

pub fn as_list<T>(&self) -> Vec<T>
where T: Decodable,

Source

pub fn val_at<T>(&self, index: usize) -> T
where T: Decodable,

Decode data at given list index into an object

Source

pub fn list_at<T>(&self, index: usize) -> Vec<T>
where T: Decodable,

Trait Implementations§

Source§

impl<'a> Debug for Rlp<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Display for Rlp<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> From<UntrustedRlp<'a>> for Rlp<'a>

Source§

fn from(rlp: UntrustedRlp<'a>) -> Rlp<'a>

Converts to this type from the input type.
Source§

impl<'a, 'view> IntoIterator for &'view Rlp<'a>
where 'a: 'view,

Source§

type Item = Rlp<'a>

The type of the elements being iterated over.
Source§

type IntoIter = RlpIterator<'a, 'view>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for Rlp<'a>

§

impl<'a> !RefUnwindSafe for Rlp<'a>

§

impl<'a> Send for Rlp<'a>

§

impl<'a> !Sync for Rlp<'a>

§

impl<'a> Unpin for Rlp<'a>

§

impl<'a> UnwindSafe for Rlp<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.