我遇到了一些问题,并且想使用task :: spawn(count)而不复制字符串。
async fn count(input: &str) -> Result<HashMap<char, usize>> {
// ...
}
async fn collect(input: &[&str]) -> Result<HashMap<char, usize>> {
// ...
for l in input.iter() {
// I would like to wirte something like:
// v.push(Box::pin(task::spawn(count(l))));
// but the borrow checker is fighting me.
// v.push(Box::pin(task::spawn(count(l)))) works if
// I copy with l.to_string() and change the function signature
// appropriately
v.push(Box::pin(count(l)));
// Pin is needed for the select_all(..)
}
// ...
}
代码可在此处找到:https://github.com/jk-jonas/parallel-letter-frequency