From aeb765b7235888f6df12bff364fd5dcec3f31b20 Mon Sep 17 00:00:00 2001 From: Valerii Hiora Date: Tue, 6 Jan 2015 15:39:06 +0200 Subject: Fallout of serialize traits changes --- src/lib.rs | 1 + src/serialization.rs | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 068b3a4..46a4509 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,6 +37,7 @@ //! #![feature(macro_rules)] +#![feature(associated_types)] #![feature(old_orphan_check)] #![deny(missing_docs)] #![cfg_attr(test, deny(warnings))] diff --git a/src/serialization.rs b/src/serialization.rs index 78e0e2b..bc56fe5 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -120,7 +120,7 @@ enum EncoderState { /// /// This function expects the type given to represent a TOML table in some form. /// If encoding encounters an error, then this function will fail the task. -pub fn encode>(t: &T) -> Value { +pub fn encode(t: &T) -> Value { let mut e = Encoder::new(); t.encode(&mut e).unwrap(); Table(e.toml) @@ -130,7 +130,7 @@ pub fn encode>(t: &T) -> Value { /// /// This function expects the type given to represent a TOML table in some form. /// If encoding encounters an error, then this function will fail the task. -pub fn encode_str>(t: &T) -> String { +pub fn encode_str(t: &T) -> String { format!("{}", encode(t)) } @@ -160,7 +160,9 @@ impl Encoder { } } -impl rustc_serialize::Encoder for Encoder { +impl rustc_serialize::Encoder for Encoder { + type Error = Error; + fn emit_nil(&mut self) -> Result<(), Error> { Ok(()) } fn emit_uint(&mut self, v: uint) -> Result<(), Error> { self.emit_i64(v as i64) @@ -369,7 +371,7 @@ impl rustc_serialize::Encoder for Encoder { /// into the type specified. If decoding fails, `None` will be returned. If a /// finer-grained error is desired, then it is recommended to use `Decodable` /// directly. -pub fn decode>(toml: Value) +pub fn decode(toml: Value) -> Option { rustc_serialize::Decodable::decode(&mut Decoder::new(toml)).ok() @@ -381,7 +383,7 @@ pub fn decode>(toml: Value) /// the TOML value into the desired type. If any error occurs `None` is return. /// If more fine-grained errors are desired, these steps should be driven /// manually. -pub fn decode_str>(s: &str) +pub fn decode_str(s: &str) -> Option { Parser::new(s).parse().and_then(|t| decode(Table(t))) @@ -426,7 +428,8 @@ impl Decoder { } } -impl rustc_serialize::Decoder for Decoder { +impl rustc_serialize::Decoder for Decoder { + type Error = DecodeError; fn read_nil(&mut self) -> Result<(), DecodeError> { match self.toml { Some(Value::String(ref s)) if s.len() == 0 => {} @@ -814,7 +817,7 @@ impl StdError for Error { #[cfg(test)] mod tests { use std::collections::{BTreeMap, HashSet}; - use rustc_serialize::{Encodable, Decodable}; + use rustc_serialize::{self, Encodable, Decodable}; use super::{Encoder, Decoder, DecodeError}; use Value; @@ -883,8 +886,8 @@ mod tests { fn application_decode_error() { #[derive(PartialEq, Show)] struct Range10(uint); - impl, E> Decodable for Range10 { - fn decode(d: &mut D) -> Result { + impl Decodable for Range10 { + fn decode(d: &mut D) -> Result { let x: uint = try!(Decodable::decode(d)); if x > 10 { Err(d.error("Value out of range!")) -- cgit v1.2.3