2 ms·
There is one case where Rust breaks this rule for the sake of simpler syntax. Send of Futures: async fn send_peekaboo() { let _r = std::rc::Rc::ne
by pornel 4y ago
There is one case where Rust breaks this rule for the sake of simpler syntax. Send of Futures:
async fn send_peekaboo() {
let _r = std::rc::Rc::new(());
// async {}.await;
}
fn is_it_send(_: impl Send) {}
is_it_send(send_peekaboo());
If you uncomment the .await line, this crates a possibility of moving thread-unsafe Rc across threads, and the Future stops being thread-safe. Rust catches this problem correctly, but it is a case where function body leaks into the signature.
- steveklabnik 4y agoSomeone pointed this out to me on Twitter, it’s a great point!