fix typos in sample code, add enum to json encoder, add test case
This commit is contained in:
parent
19dfec2aaf
commit
765961438d
2 changed files with 58 additions and 13 deletions
|
@ -122,9 +122,15 @@ pub impl Encoder: serialize::Encoder {
|
|||
fn emit_managed(&self, f: fn()) { f() }
|
||||
|
||||
fn emit_enum(&self, name: &str, f: fn()) {
|
||||
if name != "option" { die!(~"only supports option enum") }
|
||||
f()
|
||||
// emitting enums as arrays where the first
|
||||
// element provides the enum variant name
|
||||
self.wr.write_char('[');
|
||||
self.wr.write_str(name);
|
||||
self.wr.write_char(',');
|
||||
f();
|
||||
self.wr.write_char(']');
|
||||
}
|
||||
|
||||
fn emit_enum_variant(&self, _name: &str, id: uint, _cnt: uint, f: fn()) {
|
||||
if id == 0 {
|
||||
self.emit_nil();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue