Downcast this error into an `E`, taking ownership. If this error is an `E`, then `Ok(E)` is returned. Otherwise, `Err(self)` is returned. If there are multiple instances of `E` in this error's chain, then the first (as encountered by [`Error::chain`]'s iteration order) is returned. # Example ``` # use wasmtime_internal_core as wasmtime; use wasmtime::error::{Error, OutOfMemory}; let error = E
(self)
| 990 | /// ); |
| 991 | /// ``` |
| 992 | pub fn downcast<E>(self) -> Result<E, Self> |
| 993 | where |
| 994 | E: fmt::Display + fmt::Debug + Send + Sync + 'static, |
| 995 | { |
| 996 | self.error_ext_zip(|e| { |
| 997 | let result = e.inner.downcast::<E>().map_err(|inner| Self { inner }); |
| 998 | |
| 999 | #[cfg(feature = "anyhow")] |
| 1000 | let result = result.or_else(|e| { |
| 1001 | if e.inner |
| 1002 | .downcast_ref::<anyhow::Error>() |
| 1003 | .is_some_and(|e| e.is::<E>()) |
| 1004 | { |
| 1005 | let anyhow = match e.inner.downcast::<anyhow::Error>() { |
| 1006 | Ok(e) => e, |
| 1007 | Err(_) => unreachable!(), |
| 1008 | }; |
| 1009 | Ok(anyhow.downcast::<E>().unwrap()) |
| 1010 | } else { |
| 1011 | Err(e) |
| 1012 | } |
| 1013 | }); |
| 1014 | |
| 1015 | result |
| 1016 | }) |
| 1017 | } |
| 1018 | |
| 1019 | /// Downcast this error into a shared `&E` borrow. |
| 1020 | /// |
nothing calls this directly
no test coverage detected