Merge pull request #8 from crhino/rustc-62fb41c32

Update to newer rustc version
This commit is contained in:
Ty 2014-12-24 19:34:52 -06:00
commit ac6930c37d
6 changed files with 188 additions and 172 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "bincode"
version = "0.0.2"
version = "0.0.3"
authors = ["Ty Overby <ty@pre-alpha.com>"]
repository = "https://github.com/TyOverby/bincode"
@ -9,3 +9,6 @@ keywords = ["binary", "encode", "decode", "serialize", "deserialize"]
license = "MIT"
description = "A binary serialization / deserialization strategy and implementation."
[dependencies]
rustc-serialize = "0.1.4"

View File

@ -1,13 +1,13 @@
extern crate bincode;
extern crate serialize;
extern crate "rustc-serialize" as rustc_serialize;
#[deriving(Encodable, Decodable, PartialEq)]
#[deriving(RustcEncodable, RustcDecodable, PartialEq)]
struct Entity {
x: f32,
y: f32,
}
#[deriving(Encodable, Decodable, PartialEq)]
#[deriving(RustcEncodable, RustcDecodable, PartialEq)]
struct World {
entities: Vec<Entity>
}

View File

@ -2,15 +2,15 @@
#![crate_type = "rlib"]
#![crate_type = "dylib"]
extern crate serialize;
extern crate "rustc-serialize" as rustc_serialize;
use std::io::Buffer;
use std::io::MemWriter;
use std::io::MemReader;
use std::io::IoError;
use std::io::IoResult;
use serialize::Encodable;
use serialize::Decodable;
use rustc_serialize::Encodable;
use rustc_serialize::Decodable;
pub use writer::EncoderWriter;
pub use reader::DecoderReader;
@ -21,7 +21,7 @@ mod reader;
pub fn encode<'a, T: Encodable<EncoderWriter<'a, MemWriter>, IoError>>(t: &T) ->IoResult<Vec<u8>> {
let mut w = MemWriter::new();
match encode_into(t, &mut w) {
Ok(()) => Ok(w.unwrap()),
Ok(()) => Ok(w.into_inner()),
Err(e) => Err(e)
}
}

View File

@ -1,5 +1,5 @@
use std::io::{Buffer, Reader, IoError, IoResult, OtherIoError};
use serialize::Decoder;
use rustc_serialize::Decoder;
pub struct DecoderReader<'a, R: 'a> {
reader: &'a mut R
@ -70,83 +70,86 @@ impl<'a, R: Reader+Buffer> Decoder<IoError> for DecoderReader<'a, R> {
}
Ok(String::from_utf8(vector).unwrap())
}
fn read_enum<T>(&mut self, _: &str,
f: |&mut DecoderReader<'a, R>| -> IoResult<T>) -> IoResult<T> {
fn read_enum<T, F>(&mut self, _: &str, f: F) -> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult<T> {
f(self)
}
fn read_enum_variant<T>(&mut self, _: &[&str],
f: |&mut DecoderReader<'a, R>, uint| -> IoResult<T>) -> IoResult<T> {
fn read_enum_variant<T, F>(&mut self, _: &[&str], mut f: F) -> IoResult<T> where
F: FnMut(&mut DecoderReader<'a, R>, uint) -> IoResult<T> {
let id = try!(self.read_uint());
f(self, id)
}
fn read_enum_variant_arg<T>(&mut self, _: uint,
f: |&mut DecoderReader<'a, R>| -> IoResult<T>) -> IoResult<T> {
fn read_enum_variant_arg<T, F>(&mut self, _: uint, f: F) -> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult<T> {
f(self)
}
fn read_enum_struct_variant<T>(&mut self, names: &[&str],
f: |&mut DecoderReader<'a, R>, uint| -> IoResult<T>) -> IoResult<T> {
fn read_enum_struct_variant<T, F>(&mut self, names: &[&str], f: F) -> IoResult<T> where
F: FnMut(&mut DecoderReader<'a, R>, uint) -> IoResult<T> {
self.read_enum_variant(names, f)
}
fn read_enum_struct_variant_field<T>(&mut self, _: &str, f_idx: uint,
f: |&mut DecoderReader<'a, R>| -> IoResult<T>) -> IoResult<T> {
fn read_enum_struct_variant_field<T, F>(&mut self,
_: &str,
f_idx: uint,
f: F)
-> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult<T> {
self.read_enum_variant_arg(f_idx, f)
}
fn read_struct<T>(&mut self, _: &str, _: uint,
f: |&mut DecoderReader<'a, R>| -> IoResult<T>) -> IoResult<T> {
fn read_struct<T, F>(&mut self, _: &str, _: uint, f: F) -> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult<T> {
f(self)
}
fn read_struct_field<T>(&mut self, _: &str, _: uint,
f: |&mut DecoderReader<'a, R>| -> IoResult<T>) -> IoResult<T> {
fn read_struct_field<T, F>(&mut self,
_: &str,
_: uint,
f: F)
-> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult<T> {
f(self)
}
fn read_tuple<T>(&mut self, _: uint,
f: |&mut DecoderReader<'a, R>| -> IoResult<T>) ->
IoResult<T> {
fn read_tuple<T, F>(&mut self, _: uint, f: F) -> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult<T> {
f(self)
}
fn read_tuple_arg<T>(&mut self, _: uint,
f: |&mut DecoderReader<'a, R>| -> IoResult<T>) -> IoResult<T> {
fn read_tuple_arg<T, F>(&mut self, _: uint, f: F) -> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult<T> {
f(self)
}
fn read_tuple_struct<T>(&mut self, _: &str, len: uint,
f: |&mut DecoderReader<'a, R>| -> IoResult<T>) ->
IoResult<T> {
fn read_tuple_struct<T, F>(&mut self, _: &str, len: uint, f: F) -> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult<T> {
self.read_tuple(len, f)
}
fn read_tuple_struct_arg<T>(&mut self, a_idx: uint,
f: |&mut DecoderReader<'a, R>| -> IoResult<T>) -> IoResult<T> {
fn read_tuple_struct_arg<T, F>(&mut self, a_idx: uint, f: F) -> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult<T> {
self.read_tuple_arg(a_idx, f)
}
fn read_option<T>(&mut self,
f: |&mut DecoderReader<'a, R>, bool| -> IoResult<T>) ->
IoResult<T> {
fn read_option<T, F>(&mut self, mut f: F) -> IoResult<T> where
F: FnMut(&mut DecoderReader<'a, R>, bool) -> IoResult<T> {
match try!(self.reader.read_u8()) {
1 => f(self, true),
_ => f(self, false)
}
}
fn read_seq<T>(&mut self,
f: |&mut DecoderReader<'a, R>, uint| -> IoResult<T>) ->
IoResult<T> {
fn read_seq<T, F>(&mut self, f: F) -> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>, uint) -> IoResult<T> {
let len = try!(self.read_uint());
f(self, len)
}
fn read_seq_elt<T>(&mut self, _: uint,
f: |&mut DecoderReader<'a, R>| -> IoResult<T>) -> IoResult<T> {
fn read_seq_elt<T, F>(&mut self, _: uint, f: F) -> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult<T> {
f(self)
}
fn read_map<T>(&mut self,
f: |&mut DecoderReader<'a, R>, uint| -> IoResult<T>) ->
IoResult<T> {
fn read_map<T, F>(&mut self, f: F) -> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>, uint) -> IoResult<T> {
let len = try!(self.read_uint());
f(self, len)
}
fn read_map_elt_key<T>(&mut self, _: uint,
f: |&mut DecoderReader<'a, R>| -> IoResult<T>) -> IoResult<T> {
fn read_map_elt_key<T, F>(&mut self, _: uint, f: F) -> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult<T> {
f(self)
}
fn read_map_elt_val<T>(&mut self, _: uint,
f: |&mut DecoderReader<'a, R>| -> IoResult<T>) -> IoResult<T> {
fn read_map_elt_val<T, F>(&mut self, _: uint, f: F) -> IoResult<T> where
F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult<T> {
f(self)
}
fn error(&mut self, err: &str) -> IoError {

View File

@ -1,10 +1,12 @@
extern crate "rustc-serialize" as serialize;
use std::io::MemWriter;
use std::fmt::Show;
use std::io::MemReader;
use std::io::IoError;
use std::collections::HashMap;
use serialize::{
use rustc_serialize::{
Encoder,
Decoder,
Encodable,
@ -63,7 +65,7 @@ fn test_tuple() {
#[test]
fn test_basic_struct() {
#[deriving(Encodable, Decodable, PartialEq, Show)]
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Easy {
x: int,
s: String,
@ -74,13 +76,13 @@ fn test_basic_struct() {
#[test]
fn test_nested_struct() {
#[deriving(Encodable, Decodable, PartialEq, Show)]
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Easy {
x: int,
s: String,
y: uint
}
#[deriving(Encodable, Decodable, PartialEq, Show)]
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct Nest {
f: Easy,
b: uint,
@ -96,7 +98,7 @@ fn test_nested_struct() {
#[test]
fn test_struct_tuple() {
#[deriving(Encodable, Decodable, PartialEq, Show)]
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)]
struct TubStr(uint, String, f32);
the_same(TubStr(5, "hello".to_string(), 3.2));
@ -111,7 +113,7 @@ fn option() {
#[test]
fn enm() {
#[deriving(Encodable, Decodable, PartialEq, Show)]
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)]
enum TestEnum {
NoArg,
OneArg(uint),
@ -125,7 +127,7 @@ fn enm() {
#[test]
fn struct_enum() {
#[deriving(Encodable, Decodable, PartialEq, Show)]
#[deriving(RustcEncodable, RustcDecodable, PartialEq, Show)]
enum TestEnum {
NoArg,
OneArg(uint),

View File

@ -1,5 +1,5 @@
use std::io::{Writer, IoError, IoResult};
use serialize::Encoder;
use rustc_serialize::Encoder;
type EwResult = IoResult<()>;
@ -61,84 +61,92 @@ impl<'a, W: Writer> Encoder<IoError> for EncoderWriter<'a, W> {
try!(self.emit_uint(v.len()));
self.writer.write_str(v)
}
fn emit_enum(&mut self, _: &str,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_enum<F>(&mut self, __: &str, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
f(self)
}
fn emit_enum_variant(&mut self,
_: &str, v_id: uint, _: uint,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_enum_variant<F>(&mut self, _: &str,
v_id: uint,
_: uint,
f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
try!(self.emit_uint(v_id));
f(self)
}
fn emit_enum_variant_arg(&mut self, _: uint,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_enum_variant_arg<F>(&mut self, _: uint, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
f(self)
}
fn emit_enum_struct_variant(&mut self, _: &str, _: uint,
_: uint, f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_enum_struct_variant<F>(&mut self, _: &str,
_: uint,
_: uint,
f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
f(self)
}
fn emit_enum_struct_variant_field(&mut self, _: &str,
_: uint, f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_enum_struct_variant_field<F>(&mut self,
_: &str,
_: uint,
f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
f(self)
}
fn emit_struct(&mut self, _: &str, _: uint,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_struct<F>(&mut self, _: &str, _: uint, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
f(self)
}
fn emit_struct_field(&mut self, _: &str, _: uint,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_struct_field<F>(&mut self, _: &str, _: uint, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
f(self)
}
fn emit_tuple(&mut self, _: uint,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_tuple<F>(&mut self, _: uint, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
f(self)
}
fn emit_tuple_arg(&mut self, _: uint,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_tuple_arg<F>(&mut self, _: uint, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
f(self)
}
fn emit_tuple_struct(&mut self, _: &str, len: uint,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_tuple_struct<F>(&mut self, _: &str, len: uint, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
self.emit_tuple(len, f)
}
fn emit_tuple_struct_arg(&mut self, f_idx: uint,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_tuple_struct_arg<F>(&mut self, f_idx: uint, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
self.emit_tuple_arg(f_idx, f)
}
fn emit_option(&mut self,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_option<F>(&mut self, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
f(self)
}
fn emit_option_none(&mut self) -> EwResult {
self.writer.write_u8(0)
}
fn emit_option_some(&mut self,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_option_some<F>(&mut self, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
try!(self.writer.write_u8(1));
f(self)
}
fn emit_seq(&mut self, len: uint,
f: |this: &mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_seq<F>(&mut self, len: uint, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
try!(self.emit_uint(len));
f(self)
}
fn emit_seq_elt(&mut self, _: uint,
f: |this: &mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_seq_elt<F>(&mut self, _: uint, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
f(self)
}
fn emit_map(&mut self, len: uint,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_map<F>(&mut self, len: uint, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
try!(self.emit_uint(len));
f(self)
}
fn emit_map_elt_key(&mut self, _: uint,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_map_elt_key<F>(&mut self, _: uint, mut f: F) -> EwResult where
F: FnMut(&mut EncoderWriter<'a, W>) -> EwResult {
f(self)
}
fn emit_map_elt_val(&mut self, _: uint,
f: |&mut EncoderWriter<'a, W>| -> EwResult) -> EwResult {
fn emit_map_elt_val<F>(&mut self, _: uint, f: F) -> EwResult where
F: FnOnce(&mut EncoderWriter<'a, W>) -> EwResult {
f(self)
}
}