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

    pub trait Encodable {
        fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>;
    }

Trait for serializing a type.

This can be implemented for custom data types to allow them to be encoded with `Encoder` implementations. Most of Rust's built-in or standard data types (like `i32` and `Vec<T>`) have `Encodable` implementations provided by this module.

Note that, in general, you should let the compiler implement this for you by using the `derive(RustcEncodable)` attribute.

# Examples

    extern crate rustc_serialize;

    #[derive(RustcEncodable)]
    struct Point {
        x: i32,
        y: i32,
    }

This generates code equivalent to:

    extern crate rustc_serialize;
    use rustc_serialize::Encodable;
    use rustc_serialize::Encoder;

    struct Point {
        x: i32,
        y: i32,
    }

    impl Encodable for Point {
        fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
            s.emit_struct("Point", 2, |s| {
                try!(s.emit_struct_field("x", 0, |s| {
                    s.emit_i32(self.x)
                }));
                try!(s.emit_struct_field("y", 1, |s| {
                    s.emit_i32(self.y)
                }));
                Ok(())
            })
        }
    }

## Required Methods

### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`

Serialize a value using an `Encoder`.

## Implementations on Foreign Types

### `impl Encodable for usize`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for u8`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for u16`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for u32`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for u64`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for isize`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for i8`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for i16`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for i32`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for i64`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for str`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for String`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for f32`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for f64`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for bool`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for char`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for ()`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<'a, T: ?Sized + Encodable> Encodable for &'a T`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: ?Sized + Encodable> Encodable for Box<T>`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for Rc<T>`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<'a, T: Encodable + ToOwned + ?Sized> Encodable for Cow<'a, T>`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for Vec<T>`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for Option<T>`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable, E: Encodable> Encodable for Result<T, E>`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T> Encodable for PhantomData<T>`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T0: Encodable, T1: Encodable, T2: Encodable, T3: Encodable, T4: Encodable, T5: Encodable, T6: Encodable, T7: Encodable, T8: Encodable, T9: Encodable, T10: Encodable, T11: Encodable> Encodable for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T1: Encodable, T2: Encodable, T3: Encodable, T4: Encodable, T5: Encodable, T6: Encodable, T7: Encodable, T8: Encodable, T9: Encodable, T10: Encodable, T11: Encodable> Encodable for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T2: Encodable, T3: Encodable, T4: Encodable, T5: Encodable, T6: Encodable, T7: Encodable, T8: Encodable, T9: Encodable, T10: Encodable, T11: Encodable> Encodable for (T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T3: Encodable, T4: Encodable, T5: Encodable, T6: Encodable, T7: Encodable, T8: Encodable, T9: Encodable, T10: Encodable, T11: Encodable> Encodable for (T3, T4, T5, T6, T7, T8, T9, T10, T11)`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T4: Encodable, T5: Encodable, T6: Encodable, T7: Encodable, T8: Encodable, T9: Encodable, T10: Encodable, T11: Encodable> Encodable for (T4, T5, T6, T7, T8, T9, T10, T11)`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T5: Encodable, T6: Encodable, T7: Encodable, T8: Encodable, T9: Encodable, T10: Encodable, T11: Encodable> Encodable for (T5, T6, T7, T8, T9, T10, T11)`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T6: Encodable, T7: Encodable, T8: Encodable, T9: Encodable, T10: Encodable, T11: Encodable> Encodable for (T6, T7, T8, T9, T10, T11)`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T7: Encodable, T8: Encodable, T9: Encodable, T10: Encodable, T11: Encodable> Encodable for (T7, T8, T9, T10, T11)`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T8: Encodable, T9: Encodable, T10: Encodable, T11: Encodable> Encodable for (T8, T9, T10, T11)`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T9: Encodable, T10: Encodable, T11: Encodable> Encodable for (T9, T10, T11)`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T10: Encodable, T11: Encodable> Encodable for (T10, T11)`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T11: Encodable> Encodable for (T11,)`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 32]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 31]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 30]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 29]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 28]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 27]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 26]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 25]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 24]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 23]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 22]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 21]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 20]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 19]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 18]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 17]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 16]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 15]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 14]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 13]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 12]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 11]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 10]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 9]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 8]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 7]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 6]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 5]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 4]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 3]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 2]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 1]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for [T; 0]`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for Path`
[src]

#### `fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error>`
[src]

### `impl Encodable for PathBuf`
[src]

#### `fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable + Copy> Encodable for Cell<T>`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for RefCell<T>`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for Arc<T>`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for LinkedList<T>`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable> Encodable for VecDeque<T>`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<K: Encodable + Ord, V: Encodable> Encodable for BTreeMap<K, V>`
[src]

#### `fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error>`
[src]

### `impl<T: Encodable + Ord> Encodable for BTreeSet<T>`
[src]

#### `fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error>`
[src]

### `impl<K, V> Encodable for HashMap<K, V> where
K: Encodable + Hash + Eq,
V: Encodable,`
[src]

#### `fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error>`
[src]

### `impl<T> Encodable for HashSet<T> where
T: Encodable + Hash + Eq,`
[src]

#### `fn encode<E: Encoder>(&self, s: &mut E) -> Result<(), E::Error>`
[src]

## Implementors

- [src]
  `impl Encodable for Json`

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