Cherry-pick changes from rlua:

- Make Value::type_name() public
- Update CallbackError and ExternalError Display impl
This commit is contained in:
Alex Orlenko 2020-04-15 21:16:57 +01:00
parent d8b9c46d28
commit 1a788c48f1
2 changed files with 8 additions and 7 deletions

View File

@ -184,10 +184,10 @@ impl fmt::Display for Error {
Error::MismatchedRegistryKey => { Error::MismatchedRegistryKey => {
write!(fmt, "RegistryKey used from different Lua state") write!(fmt, "RegistryKey used from different Lua state")
} }
Error::CallbackError { ref traceback, ref cause } => { Error::CallbackError { ref traceback, .. } => {
write!(fmt, "callback error: {}: {}", cause, traceback) write!(fmt, "callback error: {}", traceback)
} }
Error::ExternalError(ref err) => write!(fmt, "external error: {}", err), Error::ExternalError(ref err) => write!(fmt, "{}", err),
} }
} }
} }
@ -196,7 +196,7 @@ impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> { fn source(&self) -> Option<&(dyn StdError + 'static)> {
match *self { match *self {
Error::CallbackError { ref cause, .. } => Some(cause.as_ref()), Error::CallbackError { ref cause, .. } => Some(cause.as_ref()),
Error::ExternalError(ref err) => Some(err.as_ref()), Error::ExternalError(ref err) => err.source(),
_ => None, _ => None,
} }
} }

View File

@ -48,7 +48,7 @@ pub enum Value<'lua> {
pub use self::Value::Nil; pub use self::Value::Nil;
impl<'lua> Value<'lua> { impl<'lua> Value<'lua> {
pub(crate) fn type_name(&self) -> &'static str { pub fn type_name(&self) -> &'static str {
match *self { match *self {
Value::Nil => "nil", Value::Nil => "nil",
Value::Boolean(_) => "boolean", Value::Boolean(_) => "boolean",
@ -59,7 +59,8 @@ impl<'lua> Value<'lua> {
Value::Table(_) => "table", Value::Table(_) => "table",
Value::Function(_) => "function", Value::Function(_) => "function",
Value::Thread(_) => "thread", Value::Thread(_) => "thread",
Value::UserData(_) | Value::Error(_) => "userdata", Value::UserData(_) => "userdata",
Value::Error(_) => "error",
} }
} }