pub trait Decodable: Sized {
    // Required method
    fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error>;
}
Expand description

Trait for deserializing a type.

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

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

Examples

extern crate rustc_serialize;

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

This generates code equivalent to:

extern crate rustc_serialize;
use rustc_serialize::Decodable;
use rustc_serialize::Decoder;

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

impl Decodable for Point {
    fn decode<D: Decoder>(d: &mut D) -> Result<Point, D::Error> {
        d.read_struct("Point", 2, |d| {
            let x = try!(d.read_struct_field("x", 0, |d| { d.read_i32() }));
            let y = try!(d.read_struct_field("y", 1, |d| { d.read_i32() }));
            Ok(Point{ x: x, y: y })
        })
    }
}

Required Methods§

source

fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error>

Deserialize a value using a Decoder.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Decodable for bool

source§

impl Decodable for char

source§

impl Decodable for f32

source§

impl Decodable for f64

source§

impl Decodable for i8

source§

impl Decodable for i16

source§

impl Decodable for i32

source§

impl Decodable for i64

source§

impl Decodable for isize

source§

impl Decodable for u8

source§

impl Decodable for u16

source§

impl Decodable for u32

source§

impl Decodable for u64

source§

impl Decodable for ()

source§

impl Decodable for usize

source§

impl Decodable for String

source§

impl Decodable for PathBuf

source§

impl<'a, T> Decodable for Cow<'a, T>where T: ToOwned + ?Sized, T::Owned: Decodable,

source§

fn decode<D: Decoder>(d: &mut D) -> Result<Cow<'a, T>, D::Error>

source§

impl<K, V> Decodable for HashMap<K, V>where K: Decodable + Hash + Eq, V: Decodable,

source§

fn decode<D: Decoder>(d: &mut D) -> Result<HashMap<K, V>, D::Error>

source§

impl<K: Decodable + Ord, V: Decodable> Decodable for BTreeMap<K, V>

source§

impl<T0: Decodable, T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable, T6: Decodable, T7: Decodable, T8: Decodable, T9: Decodable, T10: Decodable, T11: Decodable> Decodable for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

source§

impl<T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable, T6: Decodable, T7: Decodable, T8: Decodable, T9: Decodable, T10: Decodable, T11: Decodable> Decodable for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

source§

impl<T2: Decodable, T3: Decodable, T4: Decodable, T5: Decodable, T6: Decodable, T7: Decodable, T8: Decodable, T9: Decodable, T10: Decodable, T11: Decodable> Decodable for (T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

source§

impl<T3: Decodable, T4: Decodable, T5: Decodable, T6: Decodable, T7: Decodable, T8: Decodable, T9: Decodable, T10: Decodable, T11: Decodable> Decodable for (T3, T4, T5, T6, T7, T8, T9, T10, T11)

source§

impl<T4: Decodable, T5: Decodable, T6: Decodable, T7: Decodable, T8: Decodable, T9: Decodable, T10: Decodable, T11: Decodable> Decodable for (T4, T5, T6, T7, T8, T9, T10, T11)

source§

impl<T5: Decodable, T6: Decodable, T7: Decodable, T8: Decodable, T9: Decodable, T10: Decodable, T11: Decodable> Decodable for (T5, T6, T7, T8, T9, T10, T11)

source§

impl<T6: Decodable, T7: Decodable, T8: Decodable, T9: Decodable, T10: Decodable, T11: Decodable> Decodable for (T6, T7, T8, T9, T10, T11)

source§

impl<T7: Decodable, T8: Decodable, T9: Decodable, T10: Decodable, T11: Decodable> Decodable for (T7, T8, T9, T10, T11)

source§

impl<T8: Decodable, T9: Decodable, T10: Decodable, T11: Decodable> Decodable for (T8, T9, T10, T11)

source§

impl<T9: Decodable, T10: Decodable, T11: Decodable> Decodable for (T9, T10, T11)

source§

impl<T10: Decodable, T11: Decodable> Decodable for (T10, T11)

source§

impl<T11: Decodable> Decodable for (T11,)

source§

impl<T> Decodable for PhantomData<T>

source§

impl<T> Decodable for HashSet<T>where T: Decodable + Hash + Eq,

source§

impl<T: Decodable + Ord> Decodable for BTreeSet<T>

source§

impl<T: Decodable + Copy> Decodable for Cell<T>

source§

impl<T: Decodable + Send + Sync> Decodable for Arc<T>

source§

impl<T: Decodable> Decodable for Option<T>

source§

impl<T: Decodable> Decodable for [T; 0]

source§

impl<T: Decodable> Decodable for [T; 1]

source§

impl<T: Decodable> Decodable for [T; 2]

source§

impl<T: Decodable> Decodable for [T; 3]

source§

impl<T: Decodable> Decodable for [T; 4]

source§

impl<T: Decodable> Decodable for [T; 5]

source§

impl<T: Decodable> Decodable for [T; 6]

source§

impl<T: Decodable> Decodable for [T; 7]

source§

impl<T: Decodable> Decodable for [T; 8]

source§

impl<T: Decodable> Decodable for [T; 9]

source§

impl<T: Decodable> Decodable for [T; 10]

source§

impl<T: Decodable> Decodable for [T; 11]

source§

impl<T: Decodable> Decodable for [T; 12]

source§

impl<T: Decodable> Decodable for [T; 13]

source§

impl<T: Decodable> Decodable for [T; 14]

source§

impl<T: Decodable> Decodable for [T; 15]

source§

impl<T: Decodable> Decodable for [T; 16]

source§

impl<T: Decodable> Decodable for [T; 17]

source§

impl<T: Decodable> Decodable for [T; 18]

source§

impl<T: Decodable> Decodable for [T; 19]

source§

impl<T: Decodable> Decodable for [T; 20]

source§

impl<T: Decodable> Decodable for [T; 21]

source§

impl<T: Decodable> Decodable for [T; 22]

source§

impl<T: Decodable> Decodable for [T; 23]

source§

impl<T: Decodable> Decodable for [T; 24]

source§

impl<T: Decodable> Decodable for [T; 25]

source§

impl<T: Decodable> Decodable for [T; 26]

source§

impl<T: Decodable> Decodable for [T; 27]

source§

impl<T: Decodable> Decodable for [T; 28]

source§

impl<T: Decodable> Decodable for [T; 29]

source§

impl<T: Decodable> Decodable for [T; 30]

source§

impl<T: Decodable> Decodable for [T; 31]

source§

impl<T: Decodable> Decodable for [T; 32]

source§

impl<T: Decodable> Decodable for Box<[T]>

source§

impl<T: Decodable> Decodable for Box<T>

source§

impl<T: Decodable> Decodable for LinkedList<T>

source§

impl<T: Decodable> Decodable for VecDeque<T>

source§

impl<T: Decodable> Decodable for Rc<T>

source§

fn decode<D: Decoder>(d: &mut D) -> Result<Rc<T>, D::Error>

source§

impl<T: Decodable> Decodable for Vec<T>

source§

impl<T: Decodable> Decodable for RefCell<T>

source§

impl<T: Decodable, E: Decodable> Decodable for Result<T, E>

source§

fn decode<D: Decoder>(d: &mut D) -> Result<Result<T, E>, D::Error>

Implementors§