Advertisement
Guest User

Rust Confusing Move Semantics

a guest
Sep 30th, 2022
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. [4:50 PM]Protty: how does one send a *const T to another thread? I tried wrapping it in a custom type and doing unsafe impl Send on it but rust ignores that for some reason
  2. [4:50 PM]Inferno, Clever-ISA Shill: :thonk:
  3. [4:50 PM]Inferno, Clever-ISA Shill: That should work
  4. [4:51 PM]LegionMammal978: Did you move the entire wrapper? In the 2021 edition, if you only use wrapper.0 in the closure, it will try to capture the *const T directly
  5. [4:52 PM]Protty: I tried let w = Wrapper(x); spawn(move || { let Wrapper(x) = w }) with no luck
  6. [4:52 PM]Protty: nightly btw
  7. [4:53 PM]Protty: Heres the code. Ignoring that error, its a scoped thread impl that should be more efficient than crossbeams & probably stdlib: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=9564abdf35fb173f108ea748ee7ad312
  8. [4:54 PM]LegionMammal978: Yep, you need a let w = w; before that
  9. [4:54 PM]Protty: cringe
  10. [4:54 PM]LegionMammal978: Alternatively, impl<T: ?Sized> Deref for Wrapper<T> { ... }, and let x = *w;
  11. [4:54 PM]Inferno, Clever-ISA Shill: Welcome to rust 2021
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement