1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 extern crate serialize;
15 use std::io::{IoError, IoResult, SeekStyle};
18 use serialize::{Encodable, Encoder};
22 use rbml::io::SeekableMemWriter;
24 #[deriving(Encodable)]
29 #[deriving(Encodable)]
41 T: Encodable<json::Encoder<'a>,
42 std::io::IoError>>(val: &T,
43 wr: &'a mut SeekableMemWriter) {
44 let mut encoder = json::Encoder::new(wr);
45 val.encode(&mut encoder);
48 T: Encodable<writer::Encoder<'a, SeekableMemWriter>,
49 std::io::IoError>>(val: &T,
50 wr: &'a mut SeekableMemWriter) {
51 let mut encoder = writer::Encoder::new(wr);
52 val.encode(&mut encoder);
56 let target = Foo{baz: false,};
57 let mut wr = SeekableMemWriter::new();
58 let proto = WireProtocol::JSON;
60 WireProtocol::JSON => encode_json(&target, &mut wr),
61 WireProtocol::RBML => encode_rbml(&target, &mut wr)