Hi.
I'm trying to make thread pool which can give the Result<> returns of the sub threads.
But I can't compile due to the following error.
Codes:
pub struct ThreadPool2<'scope, T, E>
where
T: Send + 'scope,
E: Error + Send + 'scope,
{
name: &'scope str,
res: Option<Vec<Result<T, E>>>,
}
let aa: ThreadPool2<(), Box<dyn Error + Send>> = ThreadPool2 {
name:"S",
res:None,
};
Error:
error[E0277]: the size for values of type `dyn std::error::Error + Send` cannot be known at compilation time
--> src/lib.rs:300:17
|
300 | let aa: ThreadPool2<(), Box<dyn Error + Send>> = ThreadPool2 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn std::error::Error + Send`
= help: the trait `std::error::Error` is implemented for `Box<T>`
= note: required for `Box<dyn std::error::Error + Send>` to implement `std::error::Error`
note: required by a bound in `ThreadPool2`
--> src/lib.rs:284:8
|
281 | pub struct ThreadPool2<'scope, T, E>
| ----------- required by a bound in this struct
...
284 | E: Error + Send + 'scope,
| ^^^^^ required by this bound in `ThreadPool2`
How could I fix this?
Any help would be appreciated.