Slight changes for consistency
I am not actually sure what the best pattern is to import conflicting standard types, but this is at least consistent.
This commit is contained in:
parent
698785df64
commit
b3b0f17f59
21
src/error.rs
21
src/error.rs
|
@ -1,6 +1,7 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::error;
|
use std::error::Error as StdError;
|
||||||
|
use std::result::Result as StdResult;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
@ -29,10 +30,10 @@ pub enum Error {
|
||||||
CallbackError(String, Arc<Error>),
|
CallbackError(String, Arc<Error>),
|
||||||
/// Any custom external error type, mostly useful for returning external error types from
|
/// Any custom external error type, mostly useful for returning external error types from
|
||||||
/// callbacks.
|
/// callbacks.
|
||||||
ExternalError(Arc<error::Error + Send + Sync>),
|
ExternalError(Arc<StdError + Send + Sync>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
pub type Result<T> = StdResult<T, Error>;
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
@ -61,7 +62,7 @@ impl fmt::Display for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl error::Error for Error {
|
impl StdError for Error {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
match *self {
|
match *self {
|
||||||
Error::SyntaxError(_) => "lua syntax error",
|
Error::SyntaxError(_) => "lua syntax error",
|
||||||
|
@ -79,7 +80,7 @@ impl error::Error for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cause(&self) -> Option<&error::Error> {
|
fn cause(&self) -> Option<&StdError> {
|
||||||
match *self {
|
match *self {
|
||||||
Error::CallbackError(_, ref cause) => Some(cause.as_ref()),
|
Error::CallbackError(_, ref cause) => Some(cause.as_ref()),
|
||||||
Error::ExternalError(ref err) => err.cause(),
|
Error::ExternalError(ref err) => err.cause(),
|
||||||
|
@ -89,7 +90,7 @@ impl error::Error for Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
pub fn external<T: 'static + error::Error + Send + Sync>(err: T) -> Error {
|
pub fn external<T: 'static + StdError + Send + Sync>(err: T) -> Error {
|
||||||
Error::ExternalError(Arc::new(err))
|
Error::ExternalError(Arc::new(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,11 +101,11 @@ pub trait ExternalError {
|
||||||
|
|
||||||
impl<E> ExternalError for E
|
impl<E> ExternalError for E
|
||||||
where
|
where
|
||||||
E: Into<Box<error::Error + Send + Sync>>,
|
E: Into<Box<StdError + Send + Sync>>,
|
||||||
{
|
{
|
||||||
fn to_lua_err(self) -> Error {
|
fn to_lua_err(self) -> Error {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct WrapError(Box<error::Error + Send + Sync>);
|
struct WrapError(Box<StdError + Send + Sync>);
|
||||||
|
|
||||||
impl fmt::Display for WrapError {
|
impl fmt::Display for WrapError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
@ -112,7 +113,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl error::Error for WrapError {
|
impl StdError for WrapError {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
self.0.description()
|
self.0.description()
|
||||||
}
|
}
|
||||||
|
@ -126,7 +127,7 @@ pub trait ExternalResult<T> {
|
||||||
fn to_lua_err(self) -> Result<T>;
|
fn to_lua_err(self) -> Result<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> ExternalResult<T> for ::std::result::Result<T, E>
|
impl<T, E> ExternalResult<T> for StdResult<T, E>
|
||||||
where
|
where
|
||||||
E: ExternalError,
|
E: ExternalError,
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::result::{Result as StdResult};
|
||||||
|
|
||||||
use hlist_macro::{HNil, HCons};
|
use hlist_macro::{HNil, HCons};
|
||||||
|
|
||||||
use error::*;
|
use error::*;
|
||||||
|
@ -17,7 +19,7 @@ impl<'lua> FromLuaMulti<'lua> for () {
|
||||||
|
|
||||||
/// Result is convertible to `MultiValue` following the common lua idiom of returning the result
|
/// Result is convertible to `MultiValue` following the common lua idiom of returning the result
|
||||||
/// on success, or in the case of an error, returning nil followed by the error
|
/// on success, or in the case of an error, returning nil followed by the error
|
||||||
impl<'lua, T: ToLua<'lua>, E: ToLua<'lua>> ToLuaMulti<'lua> for ::std::result::Result<T, E> {
|
impl<'lua, T: ToLua<'lua>, E: ToLua<'lua>> ToLuaMulti<'lua> for StdResult<T, E> {
|
||||||
fn to_lua_multi(self, lua: &'lua Lua) -> Result<MultiValue<'lua>> {
|
fn to_lua_multi(self, lua: &'lua Lua) -> Result<MultiValue<'lua>> {
|
||||||
let mut result = MultiValue::new();
|
let mut result = MultiValue::new();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue