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

Method downcast_mut

crates/core/src/error/error.rs:1105–1138  ·  view source on GitHub ↗

Downcast this error into an exclusive `&mut E` borrow. If this error is an `E`, then `Some(&mut 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 mut

(&mut self)

Source from the content-addressed store, hash-verified

1103 /// );
1104 /// ```
1105 pub fn downcast_mut<E>(&mut self) -> Option<&mut E>
1106 where
1107 E: fmt::Display + fmt::Debug + Send + Sync + 'static,
1108 {
1109 self.error_ext_chain_mut(|e| {
1110 {
1111 // Safety: We are running into "problem case #3" of non-lexical
1112 // lifetimes: we are returning a mutable reference, which must
1113 // be live for the whole function's scope, but are accessing it
1114 // again below in the `anyhow` downcast. This is safe because
1115 // control flow ensures that the original borrow is not actually
1116 // active anymore if we didn't return.
1117 //
1118 // https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md#problem-case-3-conditional-control-flow-across-functions
1119 let e = unsafe { NonNull::from(&mut *e).as_mut() };
1120 if let Some(r) = e.inner.downcast_mut::<E>() {
1121 return Some(r);
1122 }
1123 }
1124
1125 #[cfg(feature = "anyhow")]
1126 {
1127 if let Some(result) = e
1128 .inner
1129 .downcast_mut::<anyhow::Error>()
1130 .and_then(|anyhow| anyhow.downcast_mut::<E>())
1131 {
1132 return Some(result);
1133 }
1134 }
1135
1136 None
1137 })
1138 }
1139
1140 /// Convert this error into a `Box<dyn core::error::Error>`.
1141 ///

Callers 1

get_mutMethod · 0.80

Calls 4

fromFunction · 0.85
error_ext_chain_mutMethod · 0.80
unpack_mutMethod · 0.80
as_mutMethod · 0.45

Tested by

no test coverage detected