Explicit error type for destructed callbacks

Also removes some cleverness if debug_assertions was disabled, as it really
doesn't make much of a performance difference.
This commit is contained in:
kyren
2018-02-09 21:21:29 -05:00
parent 514abd5b82
commit fe6e4bdf35
4 changed files with 82 additions and 75 deletions
+12 -2
View File
@@ -30,7 +30,13 @@ pub enum Error {
///
/// This is an error because `rlua` callbacks are FnMut and thus can only be mutably borrowed
/// once.
RecursiveCallbackError,
RecursiveCallback,
/// Either a callback or a userdata method has been called, but the callback or userdata has
/// been destructed.
///
/// This can happen either due to to being destructed in a previous __gc, or due to being
/// destructed from exiting a `Lua::scope` call.
CallbackDestructed,
/// A Rust value could not be converted to a Lua value.
ToLuaConversionError {
/// Name of the Rust type that could not be converted.
@@ -117,7 +123,11 @@ impl fmt::Display for Error {
Error::GarbageCollectorError(ref msg) => {
write!(fmt, "garbage collector error: {}", msg)
}
Error::RecursiveCallbackError => write!(fmt, "callback called recursively"),
Error::RecursiveCallback => write!(fmt, "callback called recursively"),
Error::CallbackDestructed => write!(
fmt,
"a destructed callback or destructed userdata method was called"
),
Error::ToLuaConversionError {
from,
to,