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)]
8 extern crate rustc_macros;
9 extern crate rustc_serialize;
11 // Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
13 #[allow(unused_extern_crates)]
14 extern crate rustc_driver;
16 use rustc_macros::{Decodable, Encodable};
17 use rustc_serialize::opaque::{MemDecoder, MemEncoder};
18 use rustc_serialize::{Decodable, Encodable, Encoder};
19 use std::cell::{Cell, RefCell};
21 #[derive(Encodable, Decodable)]
26 #[derive(Encodable, Decodable)]
33 let obj = B { foo: Cell::new(true), bar: RefCell::new(A { baz: 2 }) };
35 let mut encoder = MemEncoder::new();
36 obj.encode(&mut encoder);
37 let data = encoder.finish();
39 let mut decoder = MemDecoder::new(&data, 0);
40 let obj2 = B::decode(&mut decoder);
42 assert_eq!(obj.foo.get(), obj2.foo.get());
43 assert_eq!(obj.bar.borrow().baz, obj2.bar.borrow().baz);