2013-11-21 21:30:34 -08:00
|
|
|
use std::cell::RefCell;
|
2014-05-05 18:56:44 -07:00
|
|
|
use std::rc::Rc;
|
2013-08-16 21:22:06 -07:00
|
|
|
|
2014-05-05 18:56:44 -07:00
|
|
|
trait Foo {
|
2013-11-21 21:30:34 -08:00
|
|
|
fn set(&mut self, v: Rc<RefCell<A>>);
|
2013-08-16 21:22:06 -07:00
|
|
|
}
|
|
|
|
|
2014-05-05 18:56:44 -07:00
|
|
|
struct B {
|
2013-11-21 21:30:34 -08:00
|
|
|
v: Option<Rc<RefCell<A>>>
|
2013-08-16 21:22:06 -07:00
|
|
|
}
|
|
|
|
|
2014-05-05 18:56:44 -07:00
|
|
|
impl Foo for B {
|
2013-11-21 21:30:34 -08:00
|
|
|
fn set(&mut self, v: Rc<RefCell<A>>)
|
2013-08-16 21:22:06 -07:00
|
|
|
{
|
|
|
|
self.v = Some(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-05 18:56:44 -07:00
|
|
|
struct A {
|
2019-05-28 14:46:13 -04:00
|
|
|
v: Box<dyn Foo + Send>,
|
2013-08-16 21:22:06 -07:00
|
|
|
}
|
|
|
|
|
2014-05-05 18:56:44 -07:00
|
|
|
fn main() {
|
2022-07-07 04:36:10 +02:00
|
|
|
let a = A {v: Box::new(B{v: None}) as Box<dyn Foo + Send>};
|
2020-09-02 10:40:56 +03:00
|
|
|
//~^ ERROR `Rc<RefCell<A>>` cannot be sent between threads safely
|
2013-08-16 21:22:06 -07:00
|
|
|
}
|