How to get the inner error in an io::Error?


I'm using ldap3 crate and I have an issue when searching: if the search fails to find anything, the crate wraps the status object in io::Error. I've seen get_ref() in io:Error but I can't test any field of the ref as it's a &(dyn Error + Send + Sync + 'static) and not an LdapResult.

Related doc:

So my question is: how can I extract the LdapResult wrapped into the io::Error?

There is also into_inner and source methods on io::Error and std::error::Error. However they will just produce a trait object, similar to get_ref.

If you know or suspect what type the error is, you have to downcast it to the inner error to get any useful information out of it other than the Display impl.

Thanks! I didn't know the existence of this method!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.