Type

Enum Type 

Source
pub enum Type {
    Single(Cow<'static, str>),
    Value(Box<Type>),
    Alias(Box<Type>),
    Tuple(Vec<Type>),
    Table(BTreeMap<Index, Type>),
    Union(Vec<Type>),
    Array(Box<Type>),
    Map(Box<Type>, Box<Type>),
    Function {
        params: Vec<Param>,
        returns: Vec<Return>,
    },
    Enum(Vec<Type>),
    Class(Box<TypedClassBuilder>),
    Module(Box<TypedModuleBuilder>),
}
Expand description

Representation of a lua type for a rust type

Variants§

§

Single(Cow<'static, str>)

Represents a single type. i.e. string, number, 0, "literal", Example, etc…

§Example

--- @type string
--- @type number 
--- @type 0
--- @type "literal"
--- @type Example
§

Value(Box<Type>)

Represents a typed value

§Example

--- @type {type}
value = nil
§

Alias(Box<Type>)

Represents a type alias

§Example

--- @alias MyType {type}
§

Tuple(Vec<Type>)

Represents a tuple type

§Example

--- @type [number, integer, string]
§

Table(BTreeMap<Index, Type>)

Represents a table literal

§Example

--- @type { name: string, age: integer, height: number }
§

Union(Vec<Type>)

Represents a type union

§Example

--- @type string | number | "literal" | Example
§

Array(Box<Type>)

Represents an array of a single type

§Example

--- @type string[]
§

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

Represents a table with set key types and value types

§Example

--- @type { [string]: boolean }
§

Function

Represents a function with it’s parameters and return types

§Example

--- @type fun(self: any, name: string): string

Fields

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

Enum(Vec<Type>)

References a enum type.

In this instance it acts like a union since that is the closest relation between rust enums and a lua type

§Example

--- @alias {name} {type}
---  | {type}
---  | {type}
---  | {type}
§

Class(Box<TypedClassBuilder>)

Represents a class type

§Example

--- @class {name}
--- @field name string
--- @field age integer 
--- @field height number
§

Module(Box<TypedModuleBuilder>)

Represents a global table (module)

§Example

module = {
    data = nil,
    method = function(self) end,
}

or flattened

module = {}
function module:method() end
module.data = nil

Implementations§

Source§

impl Type

Source

pub const fn is_single(&self) -> bool

Returns true if the enum is Type::Single otherwise false

Source

pub const fn is_value(&self) -> bool

Returns true if the enum is Type::Value otherwise false

Source

pub const fn is_alias(&self) -> bool

Returns true if the enum is Type::Alias otherwise false

Source

pub const fn is_tuple(&self) -> bool

Returns true if the enum is Type::Tuple otherwise false

Source

pub const fn is_table(&self) -> bool

Returns true if the enum is Type::Table otherwise false

Source

pub const fn is_union(&self) -> bool

Returns true if the enum is Type::Union otherwise false

Source

pub const fn is_array(&self) -> bool

Returns true if the enum is Type::Array otherwise false

Source

pub const fn is_map(&self) -> bool

Returns true if the enum is Type::Map otherwise false

Source

pub const fn is_function(&self) -> bool

Returns true if the enum is Type::Function otherwise false

Source

pub const fn is_enum(&self) -> bool

Returns true if the enum is Type::Enum otherwise false

Source

pub const fn is_class(&self) -> bool

Returns true if the enum is Type::Class otherwise false

Source

pub const fn is_module(&self) -> bool

Returns true if the enum is Type::Module otherwise false

Source§

impl Type

Source

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

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

Source

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

Create a references the name of another defined type.

§Example
--- @class Example

--- @type Example
example = nil
use mlua_extras::typed::Type;

// This references the type named `Example`
Type::named("Example")
Source

pub fn string() -> Self

Create a lua builtin string type

Source

pub fn integer() -> Self

Create a lua builtin integer type

Source

pub fn number() -> Self

Create a lua builtin number type

Source

pub fn boolean() -> Self

Create a lua builtin boolean type

Source

pub fn nil() -> Self

Create a lua builtin nil type

Source

pub fn any() -> Self

Create a lua builtin any type

Source

pub fn lightuserdata() -> Self

Create a lua builtin lightuserdata type

Source

pub fn thread() -> Self

Create a lua builtin thread type

Source

pub fn enum(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 array(ty: Type) -> Self

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

Source

pub fn map(key: Type, value: 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(class: TypedClassBuilder) -> Self

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

Source

pub fn module(module: TypedModuleBuilder) -> Self

create a type that is a global module

Source

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

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

Source

pub fn table(items: impl IntoIterator<Item = (Index, Type)>) -> Self

A table that has defined entries.

If the goal is a map like syntax use Type::Map or Type::map instead

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<T: Into<Type>> BitOr<T> for Type

Allows to union types

§Example

use mlua_extras::typed::Type;

Type::string() | Type::nil()
Source§

type Output = Type

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl Clone for Type

Source§

fn clone(&self) -> Type

Returns a duplicate 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<const N: usize> From<[Type; N]> for Type

Source§

fn from(value: [Type; N]) -> Self

Converts to this type from the input type.
Source§

impl<T: IntoLuaTypeLiteral> From<T> for Type

Source§

fn from(value: T) -> 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 From<TypedClassBuilder> for Type

Source§

fn from(value: TypedClassBuilder) -> Self

Converts to this type from the input type.
Source§

impl From<TypedModuleBuilder> for Type

Source§

fn from(value: TypedModuleBuilder) -> Self

Converts to this type from the input type.
Source§

impl Hash for Type

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
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, 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.
Source§

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