]> git.proxmox.com Git - rustc.git/blob - src/test/ui-fulldeps/deriving-encodable-decodable-cell-refcell.rs
Update unsuspicious file list
[rustc.git] / src / test / ui-fulldeps / deriving-encodable-decodable-cell-refcell.rs
1 // run-pass
2
3 #![allow(unused_imports)]
4 // This briefly tests the capability of `Cell` and `RefCell` to implement the
5 // `Encodable` and `Decodable` traits via `#[derive(Encodable, Decodable)]`
6 #![feature(rustc_private)]
7
8 extern crate rustc_macros;
9 extern crate rustc_serialize;
10
11 use rustc_macros::{Decodable, Encodable};
12 use rustc_serialize::opaque::{MemDecoder, MemEncoder};
13 use rustc_serialize::{Decodable, Encodable, Encoder};
14 use std::cell::{Cell, RefCell};
15
16 #[derive(Encodable, Decodable)]
17 struct A {
18 baz: isize,
19 }
20
21 #[derive(Encodable, Decodable)]
22 struct B {
23 foo: Cell<bool>,
24 bar: RefCell<A>,
25 }
26
27 fn main() {
28 let obj = B { foo: Cell::new(true), bar: RefCell::new(A { baz: 2 }) };
29
30 let mut encoder = MemEncoder::new();
31 obj.encode(&mut encoder);
32 let data = encoder.finish();
33
34 let mut decoder = MemDecoder::new(&data, 0);
35 let obj2 = B::decode(&mut decoder);
36
37 assert_eq!(obj.foo.get(), obj2.foo.get());
38 assert_eq!(obj.bar.borrow().baz, obj2.bar.borrow().baz);
39 }