How can I declare this struct correctly?
use std::{error};
pub struct AppError {
msg: Option<String>,
// error: Option<anyhow::Error>, // This works
error: Option<dyn error::Error + Send + Sync + 'static>, // but I need this, not anyhow
}
the error is:
error[E0277]: the size for values of type `(dyn std::error::Error + Send + Sync + 'static)` cannot be known at compilation time
--> src/lib.rs:6:10
|
6 | error: Option<dyn error::Error + Send + Sync + 'static>, // but I need this, not anyhow
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn std::error::Error + Send + Sync + 'static)`
note: required by a bound in `Option`
For more information about this error, try `rustc --explain E0277`.
How to fix this?
SO question: https://stackoverflow.com/questions/73939213/how-can-i-declare-this-struct-which-has-an-optional-error-field.