Treat errors as `Send + Sync` to be compatible with `anyhow` crate
This commit is contained in:
parent
6f9eb82649
commit
bae424672a
17
src/error.rs
17
src/error.rs
|
@ -174,10 +174,7 @@ pub enum Error {
|
||||||
/// Returning `Err(ExternalError(...))` from a Rust callback will raise the error as a Lua
|
/// Returning `Err(ExternalError(...))` from a Rust callback will raise the error as a Lua
|
||||||
/// error. The Rust code that originally invoked the Lua code then receives a `CallbackError`,
|
/// error. The Rust code that originally invoked the Lua code then receives a `CallbackError`,
|
||||||
/// from which the original error (and a stack traceback) can be recovered.
|
/// from which the original error (and a stack traceback) can be recovered.
|
||||||
#[cfg(feature = "send")]
|
|
||||||
ExternalError(Arc<dyn StdError + Send + Sync>),
|
ExternalError(Arc<dyn StdError + Send + Sync>),
|
||||||
#[cfg(not(feature = "send"))]
|
|
||||||
ExternalError(Arc<dyn StdError>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A specialized `Result` type used by `mlua`'s API.
|
/// A specialized `Result` type used by `mlua`'s API.
|
||||||
|
@ -277,35 +274,21 @@ impl StdError for Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
#[cfg(feature = "send")]
|
|
||||||
pub fn external<T: Into<Box<dyn StdError + Send + Sync>>>(err: T) -> Error {
|
pub fn external<T: Into<Box<dyn StdError + Send + Sync>>>(err: T) -> Error {
|
||||||
Error::ExternalError(err.into().into())
|
Error::ExternalError(err.into().into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "send"))]
|
|
||||||
pub fn external<T: Into<Box<dyn StdError>>>(err: T) -> Error {
|
|
||||||
Error::ExternalError(err.into().into())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ExternalError {
|
pub trait ExternalError {
|
||||||
fn to_lua_err(self) -> Error;
|
fn to_lua_err(self) -> Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "send")]
|
|
||||||
impl<E: Into<Box<dyn StdError + Send + Sync>>> ExternalError for E {
|
impl<E: Into<Box<dyn StdError + Send + Sync>>> ExternalError for E {
|
||||||
fn to_lua_err(self) -> Error {
|
fn to_lua_err(self) -> Error {
|
||||||
Error::external(self)
|
Error::external(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "send"))]
|
|
||||||
impl<E: Into<Box<dyn StdError>>> ExternalError for E {
|
|
||||||
fn to_lua_err(self) -> Error {
|
|
||||||
Error::external(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait ExternalResult<T> {
|
pub trait ExternalResult<T> {
|
||||||
fn to_lua_err(self) -> Result<T>;
|
fn to_lua_err(self) -> Result<T>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue