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