From f1739b14a1346419a4598339aee32aab07e0d12e Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 18 Mar 2014 10:58:26 -0700 Subject: serialize: use Result All of Decoder and Encoder's methods now return a Result. Encodable.encode() and Decodable.decode() return a Result as well. fixes #12292 --- src/libworkcache/lib.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/libworkcache') diff --git a/src/libworkcache/lib.rs b/src/libworkcache/lib.rs index 3e513472027..a049279c5c4 100644 --- a/src/libworkcache/lib.rs +++ b/src/libworkcache/lib.rs @@ -203,7 +203,7 @@ impl Database { self.db_filename.display(), e.to_str()), Ok(r) => { let mut decoder = json::Decoder::new(r); - self.db_cache = Decodable::decode(&mut decoder); + self.db_cache = Decodable::decode(&mut decoder).unwrap(); } } } @@ -252,19 +252,19 @@ enum Work<'a, T> { WorkFromTask(&'a Prep<'a>, Receiver<(Exec, T)>), } -fn json_encode<'a, T:Encodable>>(t: &T) -> ~str { +fn json_encode<'a, T:Encodable, io::IoError>>(t: &T) -> ~str { let mut writer = MemWriter::new(); let mut encoder = json::Encoder::new(&mut writer as &mut io::Writer); - t.encode(&mut encoder); + let _ = t.encode(&mut encoder); str::from_utf8_owned(writer.unwrap()).unwrap() } // FIXME(#5121) -fn json_decode>(s: &str) -> T { +fn json_decode>(s: &str) -> T { debug!("json decoding: {}", s); let j = json::from_str(s).unwrap(); let mut decoder = json::Decoder::new(j); - Decodable::decode(&mut decoder) + Decodable::decode(&mut decoder).unwrap() } impl Context { @@ -392,15 +392,15 @@ impl<'a> Prep<'a> { } pub fn exec<'a, T:Send + - Encodable> + - Decodable>( + Encodable, io::IoError> + + Decodable>( &'a self, blk: proc:Send(&mut Exec) -> T) -> T { self.exec_work(blk).unwrap() } fn exec_work<'a, T:Send + - Encodable> + - Decodable>( // FIXME(#5121) + Encodable, io::IoError> + + Decodable>( // FIXME(#5121) &'a self, blk: proc:Send(&mut Exec) -> T) -> Work<'a, T> { let mut bo = Some(blk); @@ -443,8 +443,8 @@ impl<'a> Prep<'a> { } impl<'a, T:Send + - Encodable> + - Decodable> + Encodable, io::IoError> + + Decodable> Work<'a, T> { // FIXME(#5121) pub fn from_value(elt: T) -> Work<'a, T> { -- cgit 1.4.1-3-g733a5