]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-fulldeps/issue-11881.rs
Auto merge of #54919 - alexcrichton:update-cargo, r=Mark-Simulacrum
[rust.git] / src / test / run-pass-fulldeps / issue-11881.rs
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
11 #![allow(unused_must_use)]
12 #![allow(dead_code)]
13 #![allow(unused_imports)]
14
15 #![feature(rustc_private)]
16
17 extern crate serialize;
18 use serialize as rustc_serialize;
19
20 use std::io::Cursor;
21 use std::io::prelude::*;
22 use std::fmt;
23 use std::slice;
24
25 use serialize::{Encodable, Encoder};
26 use serialize::json;
27 use serialize::opaque;
28
29 #[derive(RustcEncodable)]
30 struct Foo {
31     baz: bool,
32 }
33
34 #[derive(RustcEncodable)]
35 struct Bar {
36     froboz: usize,
37 }
38
39 enum WireProtocol {
40     JSON,
41     Opaque,
42     // ...
43 }
44
45 fn encode_json<T: Encodable>(val: &T, wr: &mut Cursor<Vec<u8>>) {
46     write!(wr, "{}", json::as_json(val));
47 }
48 fn encode_opaque<T: Encodable>(val: &T, wr: Vec<u8>) {
49     let mut encoder = opaque::Encoder::new(wr);
50     val.encode(&mut encoder);
51 }
52
53 pub fn main() {
54     let target = Foo{baz: false,};
55     let proto = WireProtocol::JSON;
56     match proto {
57         WireProtocol::JSON => encode_json(&target, &mut Cursor::new(Vec::new())),
58         WireProtocol::Opaque => encode_opaque(&target, Vec::new())
59     }
60 }