Merge remote-tracking branch 'mneumann/f-serialize'

This commit is contained in:
Brian Anderson 2013-01-14 12:56:31 -08:00
commit fc582bcfce
5 changed files with 12 additions and 10 deletions

View File

@ -379,7 +379,7 @@ pub mod reader {
f()
}
fn read_struct<T>(&self, name: &str, f: fn() -> T) -> T {
fn read_struct<T>(&self, name: &str, _len: uint, f: fn() -> T) -> T {
debug!("read_struct(name=%s)", name);
f()
}
@ -658,7 +658,7 @@ pub mod writer {
}
fn emit_rec(&self, f: fn()) { f() }
fn emit_struct(&self, _name: &str, f: fn()) { f() }
fn emit_struct(&self, _name: &str, _len: uint, f: fn()) { f() }
fn emit_field(&self, name: &str, _idx: uint, f: fn()) {
self._emit_label(name);
f()

View File

@ -157,7 +157,7 @@ pub impl Encoder: serialize::Encoder {
f();
self.wr.write_char('}');
}
fn emit_struct(&self, _name: &str, f: fn()) {
fn emit_struct(&self, _name: &str, _len: uint, f: fn()) {
self.wr.write_char('{');
f();
self.wr.write_char('}');
@ -270,7 +270,7 @@ pub impl PrettyEncoder: serialize::Encoder {
self.indent -= 2;
self.wr.write_char('}');
}
fn emit_struct(&self, _name: &str, f: fn()) {
fn emit_struct(&self, _name: &str, _len: uint, f: fn()) {
self.emit_rec(f)
}
fn emit_field(&self, name: &str, idx: uint, f: fn()) {
@ -870,7 +870,7 @@ pub impl Decoder: serialize::Decoder {
move value
}
fn read_struct<T>(&self, _name: &str, f: fn() -> T) -> T {
fn read_struct<T>(&self, _name: &str, _len: uint, f: fn() -> T) -> T {
debug!("read_struct()");
let value = f();
self.pop();

View File

@ -162,7 +162,7 @@ pub impl Serializer: serialize::Encoder {
self.wr.write_str(~"}");
}
fn emit_struct(&self, name: &str, f: fn()) {
fn emit_struct(&self, name: &str, _len: uint, f: fn()) {
self.wr.write_str(fmt!("%s {", name));
f();
self.wr.write_str(~"}");

View File

@ -58,7 +58,7 @@ pub trait Encoder {
fn emit_vec_elt(&self, idx: uint, f: fn());
fn emit_rec(&self, f: fn());
fn emit_struct(&self, name: &str, f: fn());
fn emit_struct(&self, name: &str, _len: uint, f: fn());
fn emit_field(&self, f_name: &str, f_idx: uint, f: fn());
fn emit_tup(&self, len: uint, f: fn());
@ -99,7 +99,7 @@ pub trait Decoder {
fn read_vec_elt<T>(&self, idx: uint, f: fn() -> T) -> T;
fn read_rec<T>(&self, f: fn() -> T) -> T;
fn read_struct<T>(&self, name: &str, f: fn() -> T) -> T;
fn read_struct<T>(&self, name: &str, _len: uint, f: fn() -> T) -> T;
fn read_field<T>(&self, name: &str, idx: uint, f: fn() -> T) -> T;
fn read_tup<T>(&self, sz: uint, f: fn() -> T) -> T;

View File

@ -25,7 +25,7 @@ would generate two implementations like:
impl<S: Encoder> node_id: Encodable<S> {
fn encode(s: &S) {
do s.emit_struct("Node") {
do s.emit_struct("Node", 1) {
s.emit_field("id", 0, || s.emit_uint(self))
}
}
@ -33,7 +33,7 @@ would generate two implementations like:
impl<D: Decoder> node_id: Decodable {
static fn decode(d: &D) -> Node {
do d.read_struct("Node") {
do d.read_struct("Node", 1) {
Node {
id: d.read_field(~"x", 0, || decode(d))
}
@ -709,6 +709,7 @@ fn mk_struct_ser_impl(
),
~[
cx.lit_str(span, @cx.str_of(ident)),
cx.lit_uint(span, vec::len(fields)),
cx.lambda_stmts(span, fields),
]
);
@ -735,6 +736,7 @@ fn mk_struct_deser_impl(
),
~[
cx.lit_str(span, @cx.str_of(ident)),
cx.lit_uint(span, vec::len(fields)),
cx.lambda_expr(
cx.expr(
span,