use std::collections::{BTreeMap, HashMap};
use std::sync::Arc;
fn needs_send<T: Send>(_val: T) {}
async fn async_fn_a(_num: u32) {}
async fn async_fn_b(map: Arc<BTreeMap<u32, &'static u32>>) {
for (_i, v) in &*map {
async_fn_a(**v).await;
}
}
async fn async_fn_c(map: Arc<HashMap<u32, &'static u32>>) {
for (_i, v) in &*map {
async_fn_a(**v).await;
}
}
fn main() {
// this works...
let map: Arc<HashMap<u32, &'static u32>> = Arc::new(HashMap::new());
needs_send(async_fn_c(map.clone()));
// but this doesn't
let map: Arc<BTreeMap<u32, &'static u32>> = Arc::new(BTreeMap::new());
needs_send(async_fn_b(map.clone()));
}
error: implementation of `std::marker::Send` is not general enough
--> src/main.rs:24:5
|
24 | needs_send(async_fn_b(map.clone()));
| ^^^^^^^^^^
|
= note: `std::marker::Send` would have to be implemented for the type `alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Immut<'0>, u32, &'1 u32, alloc::collections::btree::node::marker::Leaf>`, for any two lifetimes `'0` and `'1`
= note: but `std::marker::Send` is actually implemented for the type `alloc::collections::btree::node::NodeRef<alloc::collections::btree::node::marker::Immut<'2>, u32, &u32, alloc::collections::btree::node::marker::Leaf>`, for some specific lifetime `'2`
(playground)