Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait TR {
- fn fn1(&self);
- }
- struct S {}
- impl TR for S {
- fn fn1(&self) {
- dbg!("fn1");
- }
- }
- struct SWrap {
- t: Box<dyn TR + Send>
- }
- impl SWrap {
- fn fn1(&self) {
- self.t.fn1();
- }
- }
- fn wrap<T: TR + Send + 'static>(t: T) -> SWrap {
- SWrap{t:Box::new(t)}
- }
- fn main() {
- let s = S{};
- let sw = wrap(s);
- let t = sw.t;
- std::thread::spawn(move || {
- t.fn1();
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement