auto merge of #13107 : seanmonstar/rust/encoder-errors, r=erickt

All of Decoder and Encoder's methods now return a Result.

Encodable.encode() and Decodable.decode() return a Result as well.

fixes #12292
This commit is contained in:
bors 2014-03-28 00:26:52 -07:00
commit ff64381c8b
27 changed files with 6558 additions and 1419 deletions

View file

@ -327,6 +327,17 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
return pm.run_plugins(krate);
}
// FIXME: remove unwrap_ after snapshot
#[cfg(stage0)]
fn unwrap_<T>(t: T) -> T {
t
}
#[cfg(not(stage0))]
fn unwrap_<T, E>(r: Result<T, E>) -> T {
r.unwrap()
}
/// This input format purely deserializes the json output file. No passes are
/// run over the deserialized output.
fn json_input(input: &str) -> Result<Output, ~str> {
@ -352,7 +363,7 @@ fn json_input(input: &str) -> Result<Output, ~str> {
let krate = match obj.pop(&~"crate") {
Some(json) => {
let mut d = json::Decoder::new(json);
Decodable::decode(&mut d)
unwrap_(Decodable::decode(&mut d))
}
None => return Err(~"malformed json"),
};
@ -384,7 +395,7 @@ fn json_output(krate: clean::Crate, res: Vec<plugins::PluginJson> ,
let mut w = MemWriter::new();
{
let mut encoder = json::Encoder::new(&mut w as &mut io::Writer);
krate.encode(&mut encoder);
unwrap_(krate.encode(&mut encoder));
}
str::from_utf8_owned(w.unwrap()).unwrap()
};