From 1b0cdad8640ddb7dce568a3337378ba78f048df7 Mon Sep 17 00:00:00 2001 From: Klimenty Titov Date: Thu, 13 Jun 2024 20:12:56 +0300 Subject: [PATCH] Added BoxDynError support --- Cargo.toml | 2 +- src/errors.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9473b88..e944456 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cc-utils" description = "Rust Fullstack utils (strict error handling, `Consider` trait, MessagePack support, etc.) for Salvo and Yew/Dioxus/Leptos/*" -version = "0.2.12" +version = "0.2.13" edition = "2021" license = "MIT" authors = ["Klimenty Titov "] diff --git a/src/errors.rs b/src/errors.rs index 57f7adb..46e005e 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -16,6 +16,8 @@ use salvo::{Depot, Request, Response}; #[cfg(feature = "salvo")] use salvo::Writer as ServerResponseWriter; +pub type BoxDynError = Box; + /// Data structure responsible for server errors. #[cfg(feature = "salvo")] #[derive(Debug)] @@ -509,6 +511,8 @@ impl_consider!(std::sync::mpsc::RecvError); impl_consider!(log::SetLoggerError); #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] impl_consider!(serde_json::Error); +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] +impl_consider!(BoxDynError); #[cfg(feature = "salvo")] #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] @@ -552,7 +556,7 @@ impl Consider for Result>> { #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] impl From>> for ErrorResponse { /// Создаёт `ErrorResponse` из данной ошибки. - fn from(_value: Option<&Box<(dyn std::any::Any + Send + Sync + 'static)>>) -> Self { + fn from(_value: Option<&Box<(dyn Any + Send + Sync + 'static)>>) -> Self { "Depot obtain failed!".into() } } @@ -658,6 +662,8 @@ impl_consider_cli!(std::io::Error); impl_consider_cli!(log::SetLoggerError); #[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))] impl_consider_cli!(serde_json::Error); +#[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))] +impl_consider_cli!(BoxDynError); #[cfg(feature = "reqwest")] #[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))]