Skip to content

Commit 52f7310

Browse files
author
Oliver Schneider
committed
make diff of next commit more readable
1 parent f7d2e9b commit 52f7310

File tree

1 file changed

+0
-197
lines changed

1 file changed

+0
-197
lines changed

src/libserialize/json.rs

-197
Original file line numberDiff line numberDiff line change
@@ -482,203 +482,6 @@ macro_rules! emit_enquoted_if_mapkey {
482482
}
483483
}
484484

485-
impl<'a> ::Encoder<EncoderError> for Encoder<'a> {
486-
fn emit_nil(&mut self) -> EncodeResult { try!(write!(self.writer, "null")); Ok(()) }
487-
488-
fn emit_uint(&mut self, v: uint) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) }
489-
fn emit_u64(&mut self, v: u64) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) }
490-
fn emit_u32(&mut self, v: u32) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) }
491-
fn emit_u16(&mut self, v: u16) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) }
492-
fn emit_u8(&mut self, v: u8) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) }
493-
494-
fn emit_int(&mut self, v: int) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) }
495-
fn emit_i64(&mut self, v: i64) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) }
496-
fn emit_i32(&mut self, v: i32) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) }
497-
fn emit_i16(&mut self, v: i16) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) }
498-
fn emit_i8(&mut self, v: i8) -> EncodeResult { emit_enquoted_if_mapkey!(self, v) }
499-
500-
fn emit_bool(&mut self, v: bool) -> EncodeResult {
501-
if v {
502-
try!(write!(self.writer, "true"));
503-
} else {
504-
try!(write!(self.writer, "false"));
505-
}
506-
Ok(())
507-
}
508-
509-
fn emit_f64(&mut self, v: f64) -> EncodeResult {
510-
emit_enquoted_if_mapkey!(self, fmt_number_or_null(v))
511-
}
512-
fn emit_f32(&mut self, v: f32) -> EncodeResult {
513-
self.emit_f64(v as f64)
514-
}
515-
516-
fn emit_char(&mut self, v: char) -> EncodeResult {
517-
self.emitting_map_key = EmittingMapKeyState::EmittedValidMapKey;
518-
escape_char(self.writer, v)
519-
}
520-
fn emit_str(&mut self, v: &str) -> EncodeResult {
521-
self.emitting_map_key = EmittingMapKeyState::EmittedValidMapKey;
522-
escape_str(self.writer, v)
523-
}
524-
525-
fn emit_enum<F>(&mut self, _name: &str, f: F) -> EncodeResult where
526-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
527-
{
528-
f(self)
529-
}
530-
531-
fn emit_enum_variant<F>(&mut self,
532-
name: &str,
533-
_id: uint,
534-
cnt: uint,
535-
f: F) -> EncodeResult where
536-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
537-
{
538-
// enums are encoded as strings or objects
539-
// Bunny => "Bunny"
540-
// Kangaroo(34,"William") => {"variant": "Kangaroo", "fields": [34,"William"]}
541-
if cnt == 0 {
542-
escape_str(self.writer, name)
543-
} else {
544-
try!(write!(self.writer, "{{\"variant\":"));
545-
try!(escape_str(self.writer, name));
546-
try!(write!(self.writer, ",\"fields\":["));
547-
try!(f(self));
548-
try!(write!(self.writer, "]}}"));
549-
Ok(())
550-
}
551-
}
552-
553-
fn emit_enum_variant_arg<F>(&mut self, idx: uint, f: F) -> EncodeResult where
554-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
555-
{
556-
if idx != 0 {
557-
try!(write!(self.writer, ","));
558-
}
559-
f(self)
560-
}
561-
562-
fn emit_enum_struct_variant<F>(&mut self,
563-
name: &str,
564-
id: uint,
565-
cnt: uint,
566-
f: F) -> EncodeResult where
567-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
568-
{
569-
self.emit_enum_variant(name, id, cnt, f)
570-
}
571-
572-
fn emit_enum_struct_variant_field<F>(&mut self,
573-
_: &str,
574-
idx: uint,
575-
f: F) -> EncodeResult where
576-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
577-
{
578-
self.emit_enum_variant_arg(idx, f)
579-
}
580-
581-
fn emit_struct<F>(&mut self, _: &str, _: uint, f: F) -> EncodeResult where
582-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
583-
{
584-
try!(write!(self.writer, "{{"));
585-
try!(f(self));
586-
try!(write!(self.writer, "}}"));
587-
Ok(())
588-
}
589-
590-
fn emit_struct_field<F>(&mut self, name: &str, idx: uint, f: F) -> EncodeResult where
591-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
592-
{
593-
if idx != 0 { try!(write!(self.writer, ",")); }
594-
try!(escape_str(self.writer, name));
595-
try!(write!(self.writer, ":"));
596-
f(self)
597-
}
598-
599-
fn emit_tuple<F>(&mut self, len: uint, f: F) -> EncodeResult where
600-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
601-
{
602-
self.emit_seq(len, f)
603-
}
604-
fn emit_tuple_arg<F>(&mut self, idx: uint, f: F) -> EncodeResult where
605-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
606-
{
607-
self.emit_seq_elt(idx, f)
608-
}
609-
610-
fn emit_tuple_struct<F>(&mut self, _name: &str, len: uint, f: F) -> EncodeResult where
611-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
612-
{
613-
self.emit_seq(len, f)
614-
}
615-
fn emit_tuple_struct_arg<F>(&mut self, idx: uint, f: F) -> EncodeResult where
616-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
617-
{
618-
self.emit_seq_elt(idx, f)
619-
}
620-
621-
fn emit_option<F>(&mut self, f: F) -> EncodeResult where
622-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
623-
{
624-
f(self)
625-
}
626-
fn emit_option_none(&mut self) -> EncodeResult { self.emit_nil() }
627-
fn emit_option_some<F>(&mut self, f: F) -> EncodeResult where
628-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
629-
{
630-
f(self)
631-
}
632-
633-
fn emit_seq<F>(&mut self, _len: uint, f: F) -> EncodeResult where
634-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
635-
{
636-
try!(write!(self.writer, "["));
637-
try!(f(self));
638-
try!(write!(self.writer, "]"));
639-
Ok(())
640-
}
641-
642-
fn emit_seq_elt<F>(&mut self, idx: uint, f: F) -> EncodeResult where
643-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
644-
{
645-
if idx != 0 {
646-
try!(write!(self.writer, ","));
647-
}
648-
f(self)
649-
}
650-
651-
fn emit_map<F>(&mut self, _len: uint, f: F) -> EncodeResult where
652-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
653-
{
654-
try!(write!(self.writer, "{{"));
655-
try!(f(self));
656-
try!(write!(self.writer, "}}"));
657-
Ok(())
658-
}
659-
660-
fn emit_map_elt_key<F>(&mut self, idx: uint, f: F) -> EncodeResult where
661-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
662-
{
663-
if idx != 0 { try!(write!(self.writer, ",")) }
664-
self.emitting_map_key = EmittingMapKeyState::Emitting;
665-
try!(f(self));
666-
if self.emitting_map_key == EmittingMapKeyState::EmittedValidMapKey {
667-
self.emitting_map_key = EmittingMapKeyState::NotEmitting;
668-
Ok(())
669-
} else {
670-
Err(EncoderError::BadHashmapKey)
671-
}
672-
}
673-
674-
fn emit_map_elt_val<F>(&mut self, _idx: uint, f: F) -> EncodeResult where
675-
F: FnOnce(&mut Encoder<'a>) -> EncodeResult,
676-
{
677-
try!(write!(self.writer, ":"));
678-
f(self)
679-
}
680-
}
681-
682485
/// Another encoder for JSON, but prints out human-readable JSON instead of
683486
/// compact data
684487
pub struct PrettyEncoder<'a> {

0 commit comments

Comments
 (0)