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 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}
;
16 #[derive(Encodable, Decodable)]
21 #[derive(Encodable, Decodable)]
28 let obj
= B { foo: Cell::new(true), bar: RefCell::new(A { baz: 2 }
) };
30 let mut encoder
= MemEncoder
::new();
31 obj
.encode(&mut encoder
);
32 let data
= encoder
.finish();
34 let mut decoder
= MemDecoder
::new(&data
, 0);
35 let obj2
= B
::decode(&mut decoder
);
37 assert_eq
!(obj
.foo
.get(), obj2
.foo
.get());
38 assert_eq
!(obj
.bar
.borrow().baz
, obj2
.bar
.borrow().baz
);