]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass-fulldeps/issue-11881.rs
New upstream version 1.13.0+dfsg1
[rustc.git] / src / test / run-pass-fulldeps / issue-11881.rs
CommitLineData
1a4d82fc
JJ
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.
4//
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.
10
c34b1796 11
d9579d0f 12#![feature(rustc_private)]
1a4d82fc 13
1a4d82fc
JJ
14extern crate serialize;
15
c34b1796
AL
16use std::io::Cursor;
17use std::io::prelude::*;
1a4d82fc 18use std::fmt;
1a4d82fc
JJ
19use std::slice;
20
21use serialize::{Encodable, Encoder};
22use serialize::json;
9e0c209e 23use serialize::opaque;
1a4d82fc
JJ
24
25#[derive(Encodable)]
26struct Foo {
27 baz: bool,
28}
29
30#[derive(Encodable)]
31struct Bar {
c34b1796 32 froboz: usize,
1a4d82fc
JJ
33}
34
35enum WireProtocol {
36 JSON,
9e0c209e 37 Opaque,
1a4d82fc
JJ
38 // ...
39}
40
c34b1796 41fn encode_json<T: Encodable>(val: &T, wr: &mut Cursor<Vec<u8>>) {
1a4d82fc
JJ
42 write!(wr, "{}", json::as_json(val));
43}
9e0c209e
SL
44fn encode_opaque<T: Encodable>(val: &T, wr: &mut Cursor<Vec<u8>>) {
45 let mut encoder = opaque::Encoder::new(wr);
1a4d82fc
JJ
46 val.encode(&mut encoder);
47}
48
49pub fn main() {
50 let target = Foo{baz: false,};
c34b1796 51 let mut wr = Cursor::new(Vec::new());
1a4d82fc
JJ
52 let proto = WireProtocol::JSON;
53 match proto {
54 WireProtocol::JSON => encode_json(&target, &mut wr),
9e0c209e 55 WireProtocol::Opaque => encode_opaque(&target, &mut wr)
1a4d82fc
JJ
56 }
57}