I am very new to rust and trying to create a Parallel.Run method of C# in rust.
C# code
Parallel.ForEach(collection, x => {
// do something with x
})
Rust Code
pub async fn parallel_run<T>(collection: Vec<T>, callback: fn(item: T) -> dyn Future<Output= ()>){
{
for item in collection
{
tokio::spawn(callback(item)).await.expect("TODO: panic message");
}
}
Compile Error
the size for values of type
dyn Future<Output = ()>
cannot be known at compilation time [E0277] doesn't have a size known at compile-time Help: the traitSized
is not implemented fordyn Future<Output = ()>
Note: required by a bound intokio::spawn
dyn Future<Output = ()>
cannot be sent between threads safely [E0277] Help: the traitSend
is not implemented fordyn Future<Output = ()>
Note: required by a bound intokio::spawn
What am I missing ??
I need to re-create Parallel.ForEach equivalent in rust