Enum mlua::prelude::LuaError[][src]

#[non_exhaustive]
pub enum LuaError {
Show variants SyntaxError { message: StdString, incomplete_input: bool, }, RuntimeError(StdString), MemoryError(StdString), GarbageCollectorError(StdString), SafetyError(StdString), MemoryLimitNotAvailable, MainThreadNotAvailable, RecursiveMutCallback, CallbackDestructed, StackError, BindError, ToLuaConversionError { from: &'static str, to: &'static str, message: Option<StdString>, }, FromLuaConversionError { from: &'static str, to: &'static str, message: Option<StdString>, }, CoroutineInactive, UserDataTypeMismatch, UserDataDestructed, UserDataBorrowError, UserDataBorrowMutError, MetaMethodRestricted(StdString), MetaMethodTypeError { method: StdString, type_name: &'static str, message: Option<StdString>, }, MismatchedRegistryKey, CallbackError { traceback: StdString, cause: Arc<Error>, }, PreviouslyResumedPanic, SerializeError(StdString), DeserializeError(StdString), ExternalError(Arc<dyn StdError + Send + Sync>),
}
Expand description

Error type returned by mlua methods.

Variants (Non-exhaustive)

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
SyntaxError
Expand description

Syntax error while parsing Lua source code.

Show fields

Fields of SyntaxError

message: StdString
Expand description

The error message as returned by Lua.

incomplete_input: bool
Expand description

true if the error can likely be fixed by appending more input to the source code.

This is useful for implementing REPLs as they can query the user for more input if this is set.

RuntimeError(StdString)
Expand description

Lua runtime error, aka LUA_ERRRUN.

The Lua VM returns this error when a builtin operation is performed on incompatible types. Among other things, this includes invoking operators on wrong types (such as calling or indexing a nil value).

MemoryError(StdString)
Expand description

Lua memory error, aka LUA_ERRMEM

The Lua VM returns this error when the allocator does not return the requested memory, aka it is an out-of-memory error.

GarbageCollectorError(StdString)
Expand description

Lua garbage collector error, aka LUA_ERRGCMM.

The Lua VM returns this error when there is an error running a __gc metamethod.

SafetyError(StdString)
Expand description

Potentially unsafe action in safe mode.

MemoryLimitNotAvailable
Expand description

Setting memory limit is not available.

This error can only happen when Lua state was not created by us and does not have the custom allocator attached.

MainThreadNotAvailable
Expand description

Main thread is not available.

This error can only happen in Lua5.1/LuaJIT module mode, when module loaded within a coroutine. These Lua versions does not have LUA_RIDX_MAINTHREAD registry key.

RecursiveMutCallback
Expand description

A mutable callback has triggered Lua code that has called the same mutable callback again.

This is an error because a mutable callback can only be borrowed mutably once.

CallbackDestructed
Expand description

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.

StackError
Expand description

Not enough stack space to place arguments to Lua functions or return values from callbacks.

Due to the way mlua works, it should not be directly possible to run out of stack space during normal use. The only way that this error can be triggered is if a Function is called with a huge number of arguments, or a rust callback returns a huge number of return values.

BindError
Expand description

Too many arguments to Function::bind

ToLuaConversionError
Expand description

A Rust value could not be converted to a Lua value.

Show fields

Fields of ToLuaConversionError

from: &'static str
Expand description

Name of the Rust type that could not be converted.

to: &'static str
Expand description

Name of the Lua type that could not be created.

message: Option<StdString>
Expand description

A message indicating why the conversion failed in more detail.

FromLuaConversionError
Expand description

A Lua value could not be converted to the expected Rust type.

Show fields

Fields of FromLuaConversionError

from: &'static str
Expand description

Name of the Lua type that could not be converted.

to: &'static str
Expand description

Name of the Rust type that could not be created.

message: Option<StdString>
Expand description

A string containing more detailed error information.

CoroutineInactive
Expand description

Thread::resume was called on an inactive coroutine.

A coroutine is inactive if its main function has returned or if an error has occurred inside the coroutine.

Thread::status can be used to check if the coroutine can be resumed without causing this error.

UserDataTypeMismatch
Expand description

An AnyUserData is not the expected type in a borrow.

This error can only happen when manually using AnyUserData, or when implementing metamethods for binary operators. Refer to the documentation of UserDataMethods for details.

UserDataDestructed
Expand description

An AnyUserData borrow failed because it has been destructed.

This error can happen either due to to being destructed in a previous __gc, or due to being destructed from exiting a Lua::scope call.

UserDataBorrowError
Expand description

An AnyUserData immutable borrow failed because it is already borrowed mutably.

This error can occur when a method on a UserData type calls back into Lua, which then tries to call a method on the same UserData type. Consider restructuring your API to prevent these errors.

UserDataBorrowMutError
Expand description

An AnyUserData mutable borrow failed because it is already borrowed.

This error can occur when a method on a UserData type calls back into Lua, which then tries to call a method on the same UserData type. Consider restructuring your API to prevent these errors.

MetaMethodRestricted(StdString)
Expand description

A MetaMethod operation is restricted (typically for __gc or __metatable).

MetaMethodTypeError
Expand description

A MetaMethod (eg. __index or __newindex) has invalid type.

Show fields

Fields of MetaMethodTypeError

method: StdStringtype_name: &'static strmessage: Option<StdString>
MismatchedRegistryKey
Expand description

A RegistryKey produced from a different Lua state was used.

CallbackError
Expand description

A Rust callback returned Err, raising the contained Error as a Lua error.

Show fields

Fields of CallbackError

traceback: StdString
Expand description

Lua call stack backtrace.

cause: Arc<Error>
Expand description

Original error returned by the Rust code.

PreviouslyResumedPanic
Expand description

A Rust panic that was previously resumed, returned again.

This error can occur only when a Rust panic resumed previously was recovered and returned again.

SerializeError(StdString)
This is supported on crate feature serialize only.
Expand description

Serialization error.

DeserializeError(StdString)
This is supported on crate feature serialize only.
Expand description

Deserialization error.

ExternalError(Arc<dyn StdError + Send + Sync>)
Expand description

A custom error.

This can be used for returning user-defined errors from callbacks.

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, from which the original error (and a stack traceback) can be recovered.

Implementations

impl Error[src]

pub fn external<T: Into<Box<dyn StdError + Send + Sync>>>(err: T) -> Error[src]

Trait Implementations

impl Clone for Error[src]

fn clone(&self) -> Error[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Error[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Display for Error[src]

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Error for Error[src]

fn source(&self) -> Option<&(dyn StdError + 'static)>[src]

The lower-level source of this error, if any. Read more

fn backtrace(&self) -> Option<&Backtrace>[src]

🔬 This is a nightly-only experimental API. (backtrace)

Returns a stack backtrace, if available, of where this error occurred. Read more

fn description(&self) -> &str1.0.0[src]

👎 Deprecated since 1.42.0:

use the Display impl or to_string()

fn cause(&self) -> Option<&dyn Error>1.0.0[src]

👎 Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

impl Error for Error[src]

fn custom<T: Display>(msg: T) -> Self[src]

Raised when there is general error when deserializing a type. Read more

fn invalid_type(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self[src]

Raised when a Deserialize receives a type different from what it was expecting. Read more

fn invalid_value(unexp: Unexpected<'_>, exp: &dyn Expected) -> Self[src]

Raised when a Deserialize receives a value of the right type but that is wrong for some other reason. Read more

fn invalid_length(len: usize, exp: &dyn Expected) -> Self[src]

Raised when deserializing a sequence or map and the input data contains too many or too few elements. Read more

fn unknown_variant(variant: &str, expected: &'static [&'static str]) -> Self[src]

Raised when a Deserialize enum type received a variant with an unrecognized name. Read more

fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self[src]

Raised when a Deserialize struct type received a field with an unrecognized name. Read more

fn missing_field(field: &'static str) -> Self[src]

Raised when a Deserialize struct type expected to receive a required field with a particular name but that field was not present in the input. Read more

fn duplicate_field(field: &'static str) -> Self[src]

Raised when a Deserialize struct type received more than one of the same field. Read more

impl Error for Error[src]

fn custom<T: Display>(msg: T) -> Self[src]

Used when a Serialize implementation encounters any error while serializing a type. Read more

impl From<AddrParseError> for Error[src]

fn from(err: AddrParseError) -> Self[src]

Performs the conversion.

impl From<Error> for Error[src]

fn from(err: IoError) -> Self[src]

Performs the conversion.

impl From<Utf8Error> for Error[src]

fn from(err: Utf8Error) -> Self[src]

Performs the conversion.

impl<'lua> FromLua<'lua> for Error[src]

fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result<Error>[src]

Performs the conversion.

impl<'lua> ToLua<'lua> for Error[src]

fn to_lua(self, _: &'lua Lua) -> Result<Value<'lua>>[src]

Performs the conversion.

Auto Trait Implementations

impl !RefUnwindSafe for Error

impl Send for Error

impl Sync for Error

impl Unpin for Error

impl !UnwindSafe for Error

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.