2015-04-20 00:56:25 -05:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// Test a very simple custom DST coercion.
|
|
|
|
|
2015-07-01 16:54:54 -05:00
|
|
|
#![feature(core, rc_weak)]
|
2015-04-20 00:56:25 -05:00
|
|
|
|
2015-06-05 12:49:23 -05:00
|
|
|
use std::cell::RefCell;
|
2015-07-01 16:54:54 -05:00
|
|
|
use std::rc::{Rc, Weak};
|
2015-04-20 00:56:25 -05:00
|
|
|
|
|
|
|
trait Baz {
|
|
|
|
fn get(&self) -> i32;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Baz for i32 {
|
|
|
|
fn get(&self) -> i32 {
|
|
|
|
*self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let a: Rc<[i32; 3]> = Rc::new([1, 2, 3]);
|
|
|
|
let b: Rc<[i32]> = a;
|
|
|
|
assert_eq!(b[0], 1);
|
|
|
|
assert_eq!(b[1], 2);
|
|
|
|
assert_eq!(b[2], 3);
|
|
|
|
|
|
|
|
let a: Rc<i32> = Rc::new(42);
|
|
|
|
let b: Rc<Baz> = a.clone();
|
|
|
|
assert_eq!(b.get(), 42);
|
|
|
|
|
2015-08-14 18:53:24 -05:00
|
|
|
let c: Weak<i32> = Rc::downgrade(&a);
|
2015-07-01 16:54:54 -05:00
|
|
|
let d: Weak<Baz> = c.clone();
|
|
|
|
|
2015-04-20 00:56:25 -05:00
|
|
|
let _c = b.clone();
|
2015-06-05 12:49:23 -05:00
|
|
|
|
|
|
|
let a: Rc<RefCell<i32>> = Rc::new(RefCell::new(42));
|
|
|
|
let b: Rc<RefCell<Baz>> = a.clone();
|
|
|
|
assert_eq!(b.borrow().get(), 42);
|
2015-08-14 18:53:24 -05:00
|
|
|
// FIXME
|
|
|
|
let c: Weak<RefCell<Baz>> = Rc::downgrade(&a) as Weak<_>;
|
2015-04-20 00:56:25 -05:00
|
|
|
}
|