diff options
| author | JustAPerson <jpriest8@ymail.com> | 2014-04-02 23:31:00 -0500 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-04-08 00:03:12 -0700 |
| commit | cdf349d442351eece966a5f8ea560f5b5ad30d80 (patch) | |
| tree | d4327224ede08680da0c5d9d3b78dc2922b49fe3 | |
| parent | 7a281718f0d32ea678f031252c0e130035fc2a80 (diff) | |
| download | rust-cdf349d442351eece966a5f8ea560f5b5ad30d80.tar.gz rust-cdf349d442351eece966a5f8ea560f5b5ad30d80.zip | |
Add test for #11881
Closes #11881. This code has been copied from the original issue and updated for modern Rust APIs.
| -rw-r--r-- | src/test/run-pass/issue-11881.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/run-pass/issue-11881.rs b/src/test/run-pass/issue-11881.rs new file mode 100644 index 00000000000..2bf846fe341 --- /dev/null +++ b/src/test/run-pass/issue-11881.rs @@ -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) + } +} |
