# Trait rlp::rlptraits::View [−] [src]

    pub trait View<'a, 'view>: Sized {
        type Prototype;
        type PayloadInfo;
        type Data;
        type Item;
        type Iter;
        fn new(bytes: &'a [u8]) -> Self;
        fn as_raw(&'view self) -> &'a [u8];
        fn prototype(&self) -> Self::Prototype;
        fn payload_info(&self) -> Self::PayloadInfo;
        fn data(&'view self) -> Self::Data;
        fn item_count(&self) -> usize;
        fn size(&self) -> usize;
        fn at(&'view self, index: usize) -> Self::Item;
        fn is_null(&self) -> bool;
        fn is_empty(&self) -> bool;
        fn is_list(&self) -> bool;
        fn is_data(&self) -> bool;
        fn is_int(&self) -> bool;
        fn iter(&'view self) -> Self::Iter;
        fn as_val<T>(&self) -> Result<T, DecoderError> where T: RlpDecodable;
        fn val_at<T>(&self, index: usize) -> Result<T, DecoderError> where T: RlpDecodable;
    }

A view into RLP encoded data

## Associated Types

### `type Prototype`

RLP prototype type

### `type PayloadInfo`

Payload info type

### `type Data`

Data type

### `type Item`

Item type

### `type Iter`

Iterator type

## Required Methods

### `fn new(bytes: &'a [u8]) -> Self`

Creates a new instance of `Rlp` reader

### `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']);
    }

### `fn prototype(&self) -> Self::Prototype`

Get the prototype of the RLP.

### `fn payload_info(&self) -> Self::PayloadInfo`

Get payload info.

### `fn data(&'view self) -> Self::Data`

Get underlieing data.

### `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);
    }

### `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);
    }

### `fn at(&'view self, index: usize) -> Self::Item`

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());
    }

### `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());
    }

### `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());
    }

### `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());
    }

### `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());
    }

### `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);
    }

### `fn iter(&'view self) -> Self::Iter`

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();
    }

### `fn as_val<T>(&self) -> Result<T, DecoderError> where T: RlpDecodable`

Decode data into an object

### `fn val_at<T>(&self, index: usize) -> Result<T, DecoderError> where T: RlpDecodable`

Decode data at given list index into an object

## Implementors

- `impl<'a, 'view> View<'a, 'view> for Rlp<'a> where 'a: 'view`
- `impl<'a, 'view> View<'a, 'view> for UntrustedRlp<'a> where 'a: 'view`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)