Enum mlua_extras::typed::Type

source ·
pub enum Type {
    Single(Cow<'static, str>),
    Value(Box<Type>),
    Alias(Box<Type>),
    Enum(Cow<'static, str>, Vec<Type>),
    Class(Box<Class>),
    Tuple(Vec<Type>),
    Struct(BTreeMap<&'static str, Type>),
    Variadic(Box<Type>),
    Union(Vec<Type>),
    Array(Box<Type>),
    Map(Box<Type>, Box<Type>),
    Function {
        params: Vec<Param>,
        returns: Vec<Type>,
    },
}
Expand description

Representation of a lua type for a rust type

Variants§

§

Single(Cow<'static, str>)

string nil boolean “literal” 3 … etc

§

Value(Box<Type>)

§

Alias(Box<Type>)

— @alias {name}

§

Enum(Cow<'static, str>, Vec<Type>)

Same as alias but with a set name predefined — @alias {name}

§

Class(Box<Class>)

— @class {name} — @field …

§

Tuple(Vec<Type>)

{ [1]: , [2]: , …etc }

§

Struct(BTreeMap<&'static str, Type>)

§

Variadic(Box<Type>)

§

Union(Vec<Type>)

§

Array(Box<Type>)

§

Map(Box<Type>, Box<Type>)

§

Function

Fields

§params: Vec<Param>
§returns: Vec<Type>

Implementations§

source§

impl Type

source

pub fn literal_string<T: Display>(value: T) -> Self

Create a lua type literal for a string. i.e. "string"

source

pub fn literal<T: Display>(value: T) -> Self

Create a lua type literal from a rust value. i.e. 3, true, etc…

source

pub fn single(value: impl Into<Cow<'static, str>>) -> Self

Create a type that has a single value. i.e. string, number, etc…

source

pub fn enum( name: impl Into<Cow<'static, str>>, types: impl IntoIterator<Item = Type>, ) -> Self

Create an enum type. This is equal to an alias

source

pub fn alias(ty: Type) -> Self

Create a type that is an alias. i.e. --- @alias {name} string

source

pub fn variadic(ty: Type) -> Self

Create a type that is variadic. i.e. ...type

source

pub fn array(ty: Type) -> Self

Create a type that is an array. i.e. { [integer]: type }

source

pub fn union(types: impl IntoIterator<Item = Type>) -> Self

Create a type that is a union. i.e. string | integer | nil

source

pub fn tuple(types: impl IntoIterator<Item = Type>) -> Self

create a type that is a tuple. i.e. { [1]: type, [2]: type }

source

pub fn class<T: TypedUserData>() -> Self

create a type that is a class. i.e. --- @class {name}

source

pub fn function<Params: TypedMultiValue, Response: TypedMultiValue>() -> Self

create a type that is a function. i.e. fun(self): number

Trait Implementations§

source§

impl AsRef<str> for Type

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl BitOr for Type

Allows to union types

§Example

use mlua_extras::typed::Type;

Type::single("string") | Type::single("nil")
source§

type Output = Type

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
source§

impl Clone for Type

source§

fn clone(&self) -> Type

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Type

source§

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

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

impl From<&'static str> for Type

source§

fn from(value: &'static str) -> Self

Converts to this type from the input type.
source§

impl From<Cow<'static, str>> for Type

source§

fn from(value: Cow<'static, str>) -> Self

Converts to this type from the input type.
source§

impl From<String> for Type

source§

fn from(value: String) -> Self

Converts to this type from the input type.
source§

impl From<Type> for Param

source§

fn from(value: Type) -> Self

Converts to this type from the input type.
source§

impl Ord for Type

source§

fn cmp(&self, other: &Type) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Type

source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 PartialOrd for Type

source§

fn partial_cmp(&self, other: &Type) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for Type

source§

impl StructuralPartialEq for Type

Auto Trait Implementations§

§

impl Freeze for Type

§

impl RefUnwindSafe for Type

§

impl Send for Type

§

impl Sync for Type

§

impl Unpin for Type

§

impl UnwindSafe for Type

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.
source§

impl<T> MaybeSend for T
where T: Send,