| 1197 | /// ``` |
| 1198 | #[inline] |
| 1199 | pub fn into_boxed_dyn_error(self) -> Box<dyn core::error::Error + Send + Sync + 'static> { |
| 1200 | /// A specialized OOM error that is zero-sized, so that it can always be |
| 1201 | /// boxed without allocation, and we can keep this method infallible (to |
| 1202 | /// match `anyhow`'s API). |
| 1203 | #[derive(Debug)] |
| 1204 | struct IntoBoxedDynCoreErrorFailure; |
| 1205 | |
| 1206 | impl core::fmt::Display for IntoBoxedDynCoreErrorFailure { |
| 1207 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1208 | write!( |
| 1209 | f, |
| 1210 | "failed to box error into `Box<dyn core::error::Error>` \ |
| 1211 | (allocation of {} bytes failed)", |
| 1212 | mem::size_of::<Error>() |
| 1213 | ) |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | impl core::error::Error for IntoBoxedDynCoreErrorFailure {} |
| 1218 | |
| 1219 | match self.inner.into_boxed_dyn_core_error() { |
| 1220 | Ok(boxed) => boxed, |
| 1221 | Err(_oom) => { |
| 1222 | // NB: `Box::new` will never actually allocate for zero-sized types. |
| 1223 | Box::new(IntoBoxedDynCoreErrorFailure) as _ |
| 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | #[cfg(feature = "backtrace")] |
| 1229 | pub(crate) fn take_backtrace(&mut self) -> Option<Backtrace> { |