]> git.lizzy.rs Git - rust.git/blob - src/test/ui-fulldeps/deriving-encodable-decodable-cell-refcell.rs
Remove support for JSON deserialization to Rust
[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 #![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;
13 use rustc_serialize::{Decodable, Encodable};
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     let mut encoder = opaque::Encoder::new(vec![]);
30     obj.encode(&mut encoder).unwrap();
31     let mut decoder = opaque::Decoder::new(&encoder.data, 0);
32     let obj2 = B::decode(&mut decoder);
33     assert_eq!(obj.foo.get(), obj2.foo.get());
34     assert_eq!(obj.bar.borrow().baz, obj2.bar.borrow().baz);
35 }