I want to write code like
struct MyError {
inner: Box<dyn Error + Send + Sync + 'static>,
}
impl Error for MyError {
fn source(&self) -> &(dyn Error + 'static) {
&self.inner
}
}
but rust doesn't seem to figure out that Error + Send + Sync + 'static
must also be Error + 'static
. Am I missing something?
EDIT My example isn't correct. It should be
impl Error for MyError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
self.inner.as_ref().map(|e| &**e as &(dyn StdError + 'static))
}
}
(note the as
cast I need to make it work). Can I avoid the cast and still get it to compile?