Oh, just to be clear: you should change `tr: ~Trait1' to `tr: ~Trait1: ' in the function signature of use_mon_trait and change `ptr_struct as ~Trait1' to `ptr_struct as ~Trait1: '.
On Fri, Feb 7, 2014 at 1:54 PM, Eric Reed <[email protected]> wrote: > ~Trait is really sugar for ~Trait: Send, so you're putting an implicit > Send bound wherever you use ~Trait. > A type meets the Send bound if it's safe to send over channels (which > really means that it contains no aliasable data or references > [alternatively, it owns all of its parts]). > Rc can never meet the Send bound (b/c of aliasability), so what you need > to do is get rid of the Send bound (not a problem since you're not actually > using it). > You can do this by replacing ~Trait with ~Trait: (notice the semicolon! > you're specifying that the bound list for ~Trait is empty). > I just tried this with your example and it compiles afterwards. > > > > On Fri, Feb 7, 2014 at 12:50 PM, Philippe Delrieu < > [email protected]> wrote: > >> Hello, >> >> I use sfml lib that contains type that has Rc<RefCell<>> fields. >> I use them in a struct that implements some trait. I have some function >> that take trait as argument. >> When I compile I have the error : error: cannot pack type `~PtrStruct`, >> which does not fulfill `Send`, as a trait bounded by Send >> >> I do some test code to be more clear: >> extern mod rsfml; >> >> use std::ptr; >> use std::rc::Rc; >> use std::cell::RefCell; >> >> pub trait Trait1 { >> fn todo(&self); >> } >> >> pub struct PtrStruct { >> this : Rc<RefCell<~str>> >> } >> >> impl Trait1 for PtrStruct { >> fn todo(&self) {} >> } >> >> >> pub trait MonTrait { >> fn use_mon_trait(&self, tr: ~Trait1); >> } >> >> pub struct UseMonTrait; >> >> impl MonTrait for UseMonTrait { >> fn use_mon_trait(&self, tr: ~Trait1) { >> tr.todo(); >> } >> } >> >> #[main] >> fn main() { >> let ptr_struct = ~PtrStruct{ this : Rc::new(RefCell::new(~"toto"))}; >> let use_ptr = UseMonTrait; >> use_ptr.use_mon_trait(ptr_struct as ~Trait1); >> } >> >> 36:34 error: cannot pack type `~PtrStruct`, which does not fulfill >> `Send`, as a trait bounded by Send >> use_ptr.use_mon_trait(ptr_struct); >> ^~~~~~~~~~ >> >> If I replace Rc<RefCell<~str>> with ~str it works. >> >> Any idea to make Rc<RefCell<>> compatible with Send trait. >> >> Philippe Delrieu >> >> _______________________________________________ >> Rust-dev mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/rust-dev >> > >
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
