Fallout of serialize traits changes
This commit is contained in:
parent
5604270dc7
commit
aeb765b723
|
@ -37,6 +37,7 @@
|
||||||
//!
|
//!
|
||||||
|
|
||||||
#![feature(macro_rules)]
|
#![feature(macro_rules)]
|
||||||
|
#![feature(associated_types)]
|
||||||
#![feature(old_orphan_check)]
|
#![feature(old_orphan_check)]
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
#![cfg_attr(test, deny(warnings))]
|
#![cfg_attr(test, deny(warnings))]
|
||||||
|
|
|
@ -120,7 +120,7 @@ enum EncoderState {
|
||||||
///
|
///
|
||||||
/// This function expects the type given to represent a TOML table in some form.
|
/// 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.
|
/// If encoding encounters an error, then this function will fail the task.
|
||||||
pub fn encode<T: rustc_serialize::Encodable<Encoder, Error>>(t: &T) -> Value {
|
pub fn encode<T: rustc_serialize::Encodable>(t: &T) -> Value {
|
||||||
let mut e = Encoder::new();
|
let mut e = Encoder::new();
|
||||||
t.encode(&mut e).unwrap();
|
t.encode(&mut e).unwrap();
|
||||||
Table(e.toml)
|
Table(e.toml)
|
||||||
|
@ -130,7 +130,7 @@ pub fn encode<T: rustc_serialize::Encodable<Encoder, Error>>(t: &T) -> Value {
|
||||||
///
|
///
|
||||||
/// This function expects the type given to represent a TOML table in some form.
|
/// 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.
|
/// If encoding encounters an error, then this function will fail the task.
|
||||||
pub fn encode_str<T: rustc_serialize::Encodable<Encoder, Error>>(t: &T) -> String {
|
pub fn encode_str<T: rustc_serialize::Encodable>(t: &T) -> String {
|
||||||
format!("{}", encode(t))
|
format!("{}", encode(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +160,9 @@ impl Encoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl rustc_serialize::Encoder<Error> for Encoder {
|
impl rustc_serialize::Encoder for Encoder {
|
||||||
|
type Error = Error;
|
||||||
|
|
||||||
fn emit_nil(&mut self) -> Result<(), Error> { Ok(()) }
|
fn emit_nil(&mut self) -> Result<(), Error> { Ok(()) }
|
||||||
fn emit_uint(&mut self, v: uint) -> Result<(), Error> {
|
fn emit_uint(&mut self, v: uint) -> Result<(), Error> {
|
||||||
self.emit_i64(v as i64)
|
self.emit_i64(v as i64)
|
||||||
|
@ -369,7 +371,7 @@ impl rustc_serialize::Encoder<Error> for Encoder {
|
||||||
/// into the type specified. If decoding fails, `None` will be returned. If a
|
/// 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`
|
/// finer-grained error is desired, then it is recommended to use `Decodable`
|
||||||
/// directly.
|
/// directly.
|
||||||
pub fn decode<T: rustc_serialize::Decodable<Decoder, DecodeError>>(toml: Value)
|
pub fn decode<T: rustc_serialize::Decodable>(toml: Value)
|
||||||
-> Option<T>
|
-> Option<T>
|
||||||
{
|
{
|
||||||
rustc_serialize::Decodable::decode(&mut Decoder::new(toml)).ok()
|
rustc_serialize::Decodable::decode(&mut Decoder::new(toml)).ok()
|
||||||
|
@ -381,7 +383,7 @@ pub fn decode<T: rustc_serialize::Decodable<Decoder, DecodeError>>(toml: Value)
|
||||||
/// the TOML value into the desired type. If any error occurs `None` is return.
|
/// 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
|
/// If more fine-grained errors are desired, these steps should be driven
|
||||||
/// manually.
|
/// manually.
|
||||||
pub fn decode_str<T: rustc_serialize::Decodable<Decoder, DecodeError>>(s: &str)
|
pub fn decode_str<T: rustc_serialize::Decodable>(s: &str)
|
||||||
-> Option<T>
|
-> Option<T>
|
||||||
{
|
{
|
||||||
Parser::new(s).parse().and_then(|t| decode(Table(t)))
|
Parser::new(s).parse().and_then(|t| decode(Table(t)))
|
||||||
|
@ -426,7 +428,8 @@ impl Decoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl rustc_serialize::Decoder<DecodeError> for Decoder {
|
impl rustc_serialize::Decoder for Decoder {
|
||||||
|
type Error = DecodeError;
|
||||||
fn read_nil(&mut self) -> Result<(), DecodeError> {
|
fn read_nil(&mut self) -> Result<(), DecodeError> {
|
||||||
match self.toml {
|
match self.toml {
|
||||||
Some(Value::String(ref s)) if s.len() == 0 => {}
|
Some(Value::String(ref s)) if s.len() == 0 => {}
|
||||||
|
@ -814,7 +817,7 @@ impl StdError for Error {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::{BTreeMap, HashSet};
|
use std::collections::{BTreeMap, HashSet};
|
||||||
use rustc_serialize::{Encodable, Decodable};
|
use rustc_serialize::{self, Encodable, Decodable};
|
||||||
|
|
||||||
use super::{Encoder, Decoder, DecodeError};
|
use super::{Encoder, Decoder, DecodeError};
|
||||||
use Value;
|
use Value;
|
||||||
|
@ -883,8 +886,8 @@ mod tests {
|
||||||
fn application_decode_error() {
|
fn application_decode_error() {
|
||||||
#[derive(PartialEq, Show)]
|
#[derive(PartialEq, Show)]
|
||||||
struct Range10(uint);
|
struct Range10(uint);
|
||||||
impl<D: ::rustc_serialize::Decoder<E>, E> Decodable<D, E> for Range10 {
|
impl Decodable for Range10 {
|
||||||
fn decode(d: &mut D) -> Result<Range10, E> {
|
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<Range10, D::Error> {
|
||||||
let x: uint = try!(Decodable::decode(d));
|
let x: uint = try!(Decodable::decode(d));
|
||||||
if x > 10 {
|
if x > 10 {
|
||||||
Err(d.error("Value out of range!"))
|
Err(d.error("Value out of range!"))
|
||||||
|
|
Loading…
Reference in a new issue