]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/deriving-encodable-decodable.rs
1 // Copyright 2013 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.
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.
11 // This actually tests a lot more than just encodable/decodable, but it gets the
19 use std
::rand
::{random, Rand}
;
20 use extra
::serialize
::*;
22 use extra
::ebml
::writer
::Encoder
;
23 use extra
::ebml
::reader
::Decoder
;
25 #[deriving(Encodable, Decodable, Eq, Rand)]
27 #[deriving(Encodable, Decodable, Eq, Rand)]
29 #[deriving(Encodable, Decodable, Eq, Rand)]
30 struct C(int
, int
, uint
);
32 #[deriving(Encodable, Decodable, Eq, Rand)]
38 #[deriving(Encodable, Decodable, Eq, Rand)]
46 #[deriving(Encodable, Decodable, Eq, Rand)]
49 #[deriving(Encodable, Decodable, Eq, Rand)]
54 fn roundtrip
<T
: Rand
+ Eq
+ Encodable
<Encoder
> + Decodable
<Decoder
>>() {
55 let obj
: T
= random();
56 let bytes
= do io
::with_bytes_writer
|w
| {
57 let mut e
= Encoder(w
);
60 let doc
= ebml
::reader
::Doc(@bytes
);
61 let mut dec
= Decoder(doc
);
62 let obj2
= Decodable
::decode(&mut dec
);
75 roundtrip
::<G
<int
>>();