-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #11881. This code has been copied from the original issue and updated for modern Rust APIs.
- Loading branch information
1 parent
7bda3df
commit dacb549
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
extern crate ser = "serialize"; | ||
|
||
use serialize = self::ser; | ||
//necessary for deriving(Encodable) | ||
use ser::{Encodable, Encoder}; | ||
use ser::json; | ||
use ser::ebml::writer; | ||
use std::io::MemWriter; | ||
use std::str::from_utf8_owned; | ||
|
||
#[deriving(Encodable)] | ||
struct Foo { | ||
baz: bool, | ||
} | ||
|
||
#[deriving(Encodable)] | ||
struct Bar { | ||
froboz: uint, | ||
} | ||
|
||
enum WireProtocol { | ||
JSON, | ||
EBML, | ||
// ... | ||
} | ||
|
||
fn encode_json<'a, | ||
T: Encodable<json::Encoder<'a>, | ||
std::io::IoError>>(val: &T, | ||
wr: &'a mut MemWriter) { | ||
let mut encoder = json::Encoder::new(wr); | ||
val.encode(&mut encoder); | ||
} | ||
fn encode_ebml<'a, | ||
T: Encodable<writer::Encoder<'a, MemWriter>, | ||
std::io::IoError>>(val: &T, | ||
wr: &'a mut MemWriter) { | ||
let mut encoder = writer::Encoder(wr); | ||
val.encode(&mut encoder); | ||
} | ||
|
||
pub fn main() { | ||
let target = Foo{baz: false,}; | ||
let mut wr = MemWriter::new(); | ||
let proto = JSON; | ||
match proto { | ||
JSON => encode_json(&target, &mut wr), | ||
EBML => encode_ebml(&target, &mut wr) | ||
} | ||
} |
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from huonw
at JustAPerson@dacb549
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging JustAPerson/rust/master = dacb549 into auto
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JustAPerson/rust/master = dacb549 merged ok, testing candidate = 171fd6fa
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some tests failed:
failure: http://buildbot.rust-lang.org/builders/auto-bsd-64-opt/builds/4906
exception: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/5043
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/5043
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/4135
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/4149
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/5143
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/4230
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/4238
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/5145
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/4230
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/4235
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android/builds/4301
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/2030
exception: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/5142
exception: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/4239
exception: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/4250
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from huonw
at JustAPerson@dacb549
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging JustAPerson/rust/master = dacb549 into auto
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JustAPerson/rust/master = dacb549 merged ok, testing candidate = 9b19c00f
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some tests failed:
exception: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/5120
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/5120
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/4212
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/4226
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/5220
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/4307
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/4315
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/5222
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/4307
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/4312
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/2107
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from huonw
at JustAPerson@dacb549
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging JustAPerson/rust/master = dacb549 into auto
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JustAPerson/rust/master = dacb549 merged ok, testing candidate = 8e1b7124
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some tests failed:
exception: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/5121
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/5121
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/4213
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/4227
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/5221
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/4308
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/4316
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/5223
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/4308
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/4313
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/2108
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from huonw
at JustAPerson@dacb549
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging JustAPerson/rust/master = dacb549 into auto
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JustAPerson/rust/master = dacb549 merged ok, testing candidate = 77cff306
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some tests failed:
exception: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/5122
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/5122
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/4214
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/4228
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/5222
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/4309
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/4317
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/5224
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/4309
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/4314
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/2109
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from huonw
at JustAPerson@dacb549
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging JustAPerson/rust/master = dacb549 into auto
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JustAPerson/rust/master = dacb549 merged ok, testing candidate = ee5c677e
dacb549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some tests failed:
failure: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/4337
exception: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/5229