Skip to content

Commit e31f7b7

Browse files
committed
std: add serialize {read,emit}_tuple{,_arg,_struct,_struct_arg}
1 parent 441df26 commit e31f7b7

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

src/libstd/ebml.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,26 @@ pub mod reader {
356356
f()
357357
}
358358
359+
fn read_tuple<T>(&self, f: &fn(uint) -> T) -> T {
360+
debug!("read_tuple()");
361+
self.read_seq(f)
362+
}
363+
364+
fn read_tuple_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
365+
debug!("read_tuple_arg(idx=%u)", idx);
366+
self.read_seq_elt(idx, f)
367+
}
368+
369+
fn read_tuple_struct<T>(&self, name: &str, f: &fn(uint) -> T) -> T {
370+
debug!("read_tuple_struct(name=%?)", name);
371+
self.read_tuple(f)
372+
}
373+
374+
fn read_tuple_struct_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
375+
debug!("read_tuple_struct_arg(idx=%u)", idx);
376+
self.read_tuple_arg(idx, f)
377+
}
378+
359379
fn read_option<T>(&self, f: &fn(bool) -> T) -> T {
360380
debug!("read_option()");
361381
do self.read_enum("Option") || {
@@ -637,6 +657,12 @@ pub mod writer {
637657
f()
638658
}
639659
660+
fn emit_tuple(&self, len: uint, f: &fn()) { self.emit_seq(len, f) }
661+
fn emit_tuple_arg(&self, idx: uint, f: &fn()) { self.emit_seq_elt(idx, f) }
662+
663+
fn emit_tuple_struct(&self, _name: &str, len: uint, f: &fn()) { self.emit_seq(len, f) }
664+
fn emit_tuple_struct_arg(&self, idx: uint, f: &fn()) { self.emit_seq_elt(idx, f) }
665+
640666
fn emit_option(&self, f: &fn()) {
641667
self.emit_enum("Option", f);
642668
}

src/libstd/json.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ impl serialize::Encoder for Encoder {
152152
f();
153153
}
154154

155+
fn emit_tuple(&self, len: uint, f: &fn()) { self.emit_seq(len, f) }
156+
fn emit_tuple_arg(&self, idx: uint, f: &fn()) { self.emit_seq_elt(idx, f) }
157+
158+
fn emit_tuple_struct(&self, _name: &str, len: uint, f: &fn()) { self.emit_seq(len, f) }
159+
fn emit_tuple_struct_arg(&self, idx: uint, f: &fn()) { self.emit_seq_elt(idx, f) }
160+
155161
fn emit_option(&self, f: &fn()) { f(); }
156162
fn emit_option_none(&self) { self.emit_nil(); }
157163
fn emit_option_some(&self, f: &fn()) { f(); }
@@ -291,6 +297,12 @@ impl serialize::Encoder for PrettyEncoder {
291297
f();
292298
}
293299

300+
fn emit_tuple(&self, len: uint, f: &fn()) { self.emit_seq(len, f) }
301+
fn emit_tuple_arg(&self, idx: uint, f: &fn()) { self.emit_seq_elt(idx, f) }
302+
303+
fn emit_tuple_struct(&self, _name: &str, len: uint, f: &fn()) { self.emit_seq(len, f) }
304+
fn emit_tuple_struct_arg(&self, idx: uint, f: &fn()) { self.emit_seq_elt(idx, f) }
305+
294306
fn emit_option(&self, f: &fn()) { f(); }
295307
fn emit_option_none(&self) { self.emit_nil(); }
296308
fn emit_option_some(&self, f: &fn()) { f(); }
@@ -901,6 +913,26 @@ impl serialize::Decoder for Decoder {
901913
}
902914
}
903915
916+
fn read_tuple<T>(&self, f: &fn(uint) -> T) -> T {
917+
debug!("read_tuple()");
918+
self.read_seq(f)
919+
}
920+
921+
fn read_tuple_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
922+
debug!("read_tuple_arg(idx=%u)", idx);
923+
self.read_seq_elt(idx, f)
924+
}
925+
926+
fn read_tuple_struct<T>(&self, name: &str, f: &fn(uint) -> T) -> T {
927+
debug!("read_tuple_struct(name=%?)", name);
928+
self.read_tuple(f)
929+
}
930+
931+
fn read_tuple_struct_arg<T>(&self, idx: uint, f: &fn() -> T) -> T {
932+
debug!("read_tuple_struct_arg(idx=%u)", idx);
933+
self.read_tuple_arg(idx, f)
934+
}
935+
904936
fn read_option<T>(&self, f: &fn(bool) -> T) -> T {
905937
match self.stack.pop() {
906938
Null => f(false),

src/libstd/serialize.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ pub trait Encoder {
5656
#[cfg(stage3)]
5757
fn emit_struct_field(&self, f_name: &str, f_idx: uint, f: &fn());
5858

59+
fn emit_tuple(&self, len: uint, f: &fn());
60+
fn emit_tuple_arg(&self, idx: uint, f: &fn());
61+
62+
fn emit_tuple_struct(&self, name: &str, len: uint, f: &fn());
63+
fn emit_tuple_struct_arg(&self, f_idx: uint, f: &fn());
64+
5965
// Specialized types:
6066
fn emit_option(&self, f: &fn());
6167
fn emit_option_none(&self);
@@ -102,6 +108,12 @@ pub trait Decoder {
102108
#[cfg(stage3)]
103109
fn read_struct_field<T>(&self, f_name: &str, f_idx: uint, f: &fn() -> T) -> T;
104110

111+
fn read_tuple<T>(&self, f: &fn(uint) -> T) -> T;
112+
fn read_tuple_arg<T>(&self, a_idx: uint, f: &fn() -> T) -> T;
113+
114+
fn read_tuple_struct<T>(&self, s_name: &str, f: &fn(uint) -> T) -> T;
115+
fn read_tuple_struct_arg<T>(&self, a_idx: uint, f: &fn() -> T) -> T;
116+
105117
// Specialized types:
106118
fn read_option<T>(&self, f: &fn(bool) -> T) -> T;
107119

src/libsyntax/ext/auto_encode.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,20 @@ mod test {
12601260
self.add_to_log(CallToEmitField (name.to_str(),idx)); f();
12611261
}
12621262
1263+
fn emit_tuple(&self, _len: uint, f: &fn()) {
1264+
self.add_unknown_to_log(); f();
1265+
}
1266+
fn emit_tuple_arg(&self, _idx: uint, f: &fn()) {
1267+
self.add_unknown_to_log(); f();
1268+
}
1269+
1270+
fn emit_tuple_struct(&self, _name: &str, _len: uint, f: &fn()) {
1271+
self.add_unknown_to_log(); f();
1272+
}
1273+
fn emit_tuple_struct_arg(&self, _idx: uint, f: &fn()) {
1274+
self.add_unknown_to_log(); f();
1275+
}
1276+
12631277
fn emit_option(&self, f: &fn()) {
12641278
self.add_to_log(CallToEmitOption);
12651279
f();

0 commit comments

Comments
 (0)