# [−][src]Trait rustc_serialize::DecoderHelpers

    pub trait DecoderHelpers: Decoder {
        fn read_to_vec<T, F>(&mut self, f: F) -> Result<Vec<T>, Self::Error>
        where
            F: FnMut(&mut Self) -> Result<T, Self::Error>;
    }

Trait with helper functions for implementing `Decodable`.

This trait is implemented for everything that implements `Decoder`. `Decodable` implementations can make use of it to make their implementations easier.

## Required methods

### `fn read_to_vec<T, F>(&mut self, f: F) -> Result<Vec<T>, Self::Error> where
F: FnMut(&mut Self) -> Result<T, Self::Error>,`

Read a sequence into a vector.

Storing sequences as vectors is a common pattern. This method makes deserializing such sequences easier by wrapping the calls to `Decoder::read_seq` and `Decoder::read_seq_elt`.

# Examples

    use rustc_serialize::Decodable;
    use rustc_serialize::Decoder;
    use rustc_serialize::DecoderHelpers;

    struct NumberSequence {
        elements: Vec<i32>,
    }

    impl Decodable for NumberSequence {
        fn decode<D: Decoder>(d: &mut D) -> Result<NumberSequence, D::Error> {
            d.read_struct("NumberSequence", 2, |d| {
                Ok(NumberSequence{
                    elements: try!(d.read_struct_field("elements", 0, |d| {
                        d.read_to_vec(|d| { d.read_i32() })
                    }))
                })
            })
        }
    }

Loading content...

## Implementors

### `impl<D: Decoder> DecoderHelpers for D`[src]

#### `fn read_to_vec<T, F>(&mut self, f: F) -> Result<Vec<T>, D::Error> where
F: FnMut(&mut D) -> Result<T, D::Error>,` [src]

Loading content...

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse 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`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)