MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / downcast

Method downcast

crates/core/src/error/error.rs:992–1017  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 ///

Callers

nothing calls this directly

Calls 9

OkFunction · 0.85
fromFunction · 0.85
error_ext_zipMethod · 0.80
unchecked_oomMethod · 0.80
unwrapMethod · 0.45
is_oomMethod · 0.45
writeMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected