Skip to content

Commit

Permalink
Add test for #11881
Browse files Browse the repository at this point in the history
Closes #11881.

This code has been copied from the original issue and updated for
modern Rust APIs.
  • Loading branch information
JustAPerson committed Apr 3, 2014
1 parent 7bda3df commit dacb549
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/test/run-pass/issue-11881.rs
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)
}
}

20 comments on commit dacb549

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 4, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 4, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 4, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 4, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 7, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 7, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 7, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 7, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 7, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 7, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 7, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 7, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 7, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 8, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 8, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 8, 2014

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

@bors
Copy link
Contributor

@bors bors commented on dacb549 Apr 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.