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 => {
write!(fmt, "RegistryKey used from different Lua state")
}
Error::CallbackError { ref traceback, ref cause } => {
write!(fmt, "callback error: {}: {}", cause, traceback)
Error::CallbackError { ref 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)> {
match *self {
Error::CallbackError { ref cause, .. } => Some(cause.as_ref()),
Error::ExternalError(ref err) => Some(err.as_ref()),
Error::ExternalError(ref err) => err.source(),
_ => None,
}
}

View File

@ -48,18 +48,19 @@ pub enum Value<'lua> {
pub use self::Value::Nil;
impl<'lua> Value<'lua> {
pub(crate) fn type_name(&self) -> &'static str {
pub fn type_name(&self) -> &'static str {
match *self {
Value::Nil => "nil",
Value::Boolean(_) => "boolean",
Value::LightUserData(_) => "light userdata",
Value::LightUserData(_) => "lightuserdata",
Value::Integer(_) => "integer",
Value::Number(_) => "number",
Value::String(_) => "string",
Value::Table(_) => "table",
Value::Function(_) => "function",
Value::Thread(_) => "thread",
Value::UserData(_) | Value::Error(_) => "userdata",
Value::UserData(_) => "userdata",
Value::Error(_) => "error",
}
}