3 ms·
Async rust isn't pretty. If you are using async rust, and want to borrow data, use an Arc<T>. In fact, if you ever use tokio::spawn, you will have to use Arc<
by throwaway23342 4y ago
Async rust isn't pretty.
If you are using async rust, and want to borrow data, use an Arc<T>.
In fact, if you ever use tokio::spawn, you will have to use Arc<T> anyway because it requires 'static lifetime.
- Hirrolot 4y agoTrue about 'static. Sometimes I think I need an IDE shortcut for `Send + Sync + 'static`. Like `if err != nil`, you know :))
- estebank 4y agoThe trait_alias[1] nightly feature might be what you want :) It was dormant for a long time, but it seems like it might be getting some love towards stabilization (or outright removal, I guess) at some point in the medium future. [1]: https://doc.rust-lang.org/beta/unstable-book/language-features/trait-alias.html https://doc.rust-lang.org/beta/unstable-book/language-featur...
- pkolaczk 4y agoYou can also use Box::leak to obtain 'static references to stuff that lives till the end of the program.