Closed
Description
Now it's impossible to implement Decodable for a map with different value types
because read_* methods lose the stack head anyway.
Decodable doesn't have a method returning the stack head as-is without any type casting.
Let's look a case where Json dictionary has values with int and String types.
extern crate serialize;
use serialize::{Decodable, Decoder};
use serialize::json::{Json, Boolean, String, Null, I64, U64, F64};
use serialize::json;
#[deriving(Show)]
struct Primitive(Json);
impl<S: Decoder<E>, E> Decodable<S, E> for Primitive {
fn decode(decoder: &mut S) -> Result<Primitive, E> {
match decoder.pop() {
n @ I64(_) => Primitive(n),
n @ U64(_) => Primitive(n),
n @ F64(_) => Primitive(n),
s @ String(_) => Primitive(s),
bad => fail!("bad {}", bad)
}
}
}
Metadata
Metadata
Assignees
Labels
No labels