Skip to main content

MetaMethod

Enum MetaMethod 

Source
#[non_exhaustive]
pub enum MetaMethod {
Show 26 variants Add, Sub, Mul, Div, Mod, Pow, IDiv, BAnd, BOr, BXor, Shl, Shr, BNot, Unm, Concat, Len, Eq, Lt, Le, Index, NewIndex, Call, ToString, Pairs, Close, Gc,
}
Expand description

Public metamethod kinds for UserdataMethods::add_meta_method.

Maps 1:1 onto the dispatcher’s internal Mm enum. Listed explicitly so the public surface doesn’t leak Mm’s discriminant layout — Mm stays pub(crate) in exec.rs.

Not all Mm variants are exposed: Mm::Metatable (the __metatable guard) and Mm::Name are set indirectly via LuaUserdata::type_name and getmetatable; surfacing them as add_meta_method targets would be confusing.

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.
§

Add

__add — binary +.

§

Sub

__sub — binary -.

§

Mul

__mul — binary *.

§

Div

__div — binary /.

§

Mod

__mod — binary %.

§

Pow

__pow — binary ^.

§

IDiv

__idiv — binary //.

§

BAnd

__band — binary &.

§

BOr

__bor — binary |.

§

BXor

__bxor — binary ~ (bitwise xor).

§

Shl

__shl<<.

§

Shr

__shr>>.

§

BNot

__bnot — unary ~.

§

Unm

__unm — unary -.

§

Concat

__concat — binary ...

§

Len

__len — unary #.

§

Eq

__eq==.

§

Lt

__lt<.

§

Le

__le<=.

§

Index

__index — non-existent key lookup. Setting this directly overrides the per-method dispatch table installed by UserdataMethods::add_method etc., so only use it when you want full control of the lookup; the trait’s default __index is a table of add_method entries.

§

NewIndex

__newindex — non-existent key assignment.

§

Call

__callobj(args).

§

ToString

__tostringtostring(obj).

§

Pairs

__pairspairs(obj) (5.2+).

§

Close

__close — to-be-closed handler (5.4+).

§

Gc

__gc — finalizer. The metatable’s __gc fires before Rust’s Drop on the host payload.

Implementations§

Source§

impl MetaMethod

Source

pub const fn name(self) -> &'static str

Lua-side string spelling of this metamethod ("__add", "__gc", …).

Trait Implementations§

Source§

impl Clone for MetaMethod

Source§

fn clone(&self) -> MetaMethod

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for MetaMethod

Source§

impl Debug for MetaMethod

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for MetaMethod

Source§

impl PartialEq for MetaMethod

Source§

fn eq(&self, other: &MetaMethod) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for MetaMethod

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.