]> git.lizzy.rs Git - rust.git/blob - src/test/ui-fulldeps/deriving-encodable-decodable-cell-refcell.rs
Do not use Cortex-M0 since Qemu is too old
[rust.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
7
8 #![feature(rustc_private)]
9
10 extern crate serialize as rustc_serialize;
11
12 use std::cell::{Cell, RefCell};
13 use rustc_serialize::{Encodable, Decodable};
14 use rustc_serialize::json;
15
16 #[derive(RustcEncodable, RustcDecodable)]
17 struct A {
18     baz: isize
19 }
20
21 #[derive(RustcEncodable, RustcDecodable)]
22 struct B {
23     foo: Cell<bool>,
24     bar: RefCell<A>,
25 }
26
27 fn main() {
28     let obj = B {
29         foo: Cell::new(true),
30         bar: RefCell::new( A { baz: 2 } )
31     };
32     let s = json::encode(&obj).unwrap();
33     let obj2: B = json::decode(&s).unwrap();
34     assert_eq!(obj.foo.get(), obj2.foo.get());
35     assert_eq!(obj.bar.borrow().baz, obj2.bar.borrow().baz);
36 }