dtolnay/anyhow

as_ref() type must be known at this point

Opened this issue · 0 comments

Hi,

I have noticed that calling as_ref() on error returned from anyhow::Result<T> always errors with type must be known at this point. It seems that simply casting to dyn Error works fine however requires that weird hoop before I can call my own traits implemented for anything that looks like std::error::Error:

let dyn_error = err.as_ref() as &dyn std::error::Error;

I looked at the source code and I am genuinely confused, what's going on there and how can one access &dyn std::error::Error from anyhow::Error without going through explicit cast?

Thanks.