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

Method downcast_ref

crates/core/src/error/error.rs:1052–1068  ·  view source on GitHub ↗

Downcast this error into a shared `&E` borrow. If this error is an `E`, then `Some(&E)` is returned. Otherwise, `None` 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 = Error::

(&self)

Source from the content-addressed store, hash-verified

1050 /// );
1051 /// ```
1052 pub fn downcast_ref<E>(&self) -> Option<&E>
1053 where
1054 E: fmt::Display + fmt::Debug + Send + Sync + 'static,
1055 {
1056 self.error_ext_chain().find_map(|e| {
1057 let result = e.inner.downcast_ref::<E>();
1058
1059 #[cfg(feature = "anyhow")]
1060 let result = result.or_else(|| {
1061 e.inner
1062 .downcast_ref::<anyhow::Error>()
1063 .and_then(|anyhow| anyhow.downcast_ref::<E>())
1064 });
1065
1066 result
1067 })
1068 }
1069
1070 /// Downcast this error into an exclusive `&mut E` borrow.
1071 ///

Callers

nothing calls this directly

Calls 4

fromFunction · 0.85
error_ext_chainMethod · 0.80
unpackMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected