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<TypedClass>),
}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 ExampleValue(Box<Type>)
Alias(Box<Type>)
Tuple(Vec<Type>)
Table(BTreeMap<Index, Type>)
Union(Vec<Type>)
Array(Box<Type>)
Map(Box<Type>, Box<Type>)
Function
Represents a function with it’s parameters and return types
§Example
--- @type fun(self: any, name: string): stringEnum(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<TypedClass>)
Represents a class type
§Example
--- @class {name}
--- @field name string
--- @field age integer
--- @field height numberImplementations§
Source§impl Type
impl Type
Sourcepub const fn is_function(&self) -> bool
pub const fn is_function(&self) -> bool
Returns true if the enum is Type::Function otherwise false
Source§impl Type
impl Type
Sourcepub fn literal<T: IntoLuaTypeLiteral>(value: T) -> Self
pub fn literal<T: IntoLuaTypeLiteral>(value: T) -> Self
Create a lua type literal from a rust value. i.e. 3, true, etc…
Sourcepub fn named(value: impl Into<Cow<'static, str>>) -> Self
pub fn named(value: impl Into<Cow<'static, str>>) -> Self
Create a reference to a name of another defined type.
§Example
--- @class Example
--- @type Example
example = niluse mlua_extras::typed::Type;
// This reference the type named `Example`
Type::named("Example");Sourcepub fn lightuserdata() -> Self
pub fn lightuserdata() -> Self
Create a lua builtin lightuserdata type
Sourcepub fn enum(types: impl IntoIterator<Item = Type>) -> Self
pub fn enum(types: impl IntoIterator<Item = Type>) -> Self
Create an enum type. This is equal to an alias
Sourcepub fn map(key: Type, value: Type) -> Self
pub fn map(key: Type, value: Type) -> Self
Create a type that is an array. i.e. { [integer]: type }
Sourcepub fn union(types: impl IntoIterator<Item = Type>) -> Self
pub fn union(types: impl IntoIterator<Item = Type>) -> Self
Create a type that is a union. i.e. string | integer | nil
Sourcepub fn tuple(types: impl IntoIterator<Item = Type>) -> Self
pub fn tuple(types: impl IntoIterator<Item = Type>) -> Self
create a type that is a tuple. i.e. { [1]: type, [2]: type }
Sourcepub fn class(class: TypedClass) -> Self
pub fn class(class: TypedClass) -> Self
create a type that is a class. i.e. --- @class {name}
Sourcepub fn function<Params: TypedMultiValue, Response: TypedMultiValue>(
params: Vec<(String, String)>,
returns: Vec<String>,
) -> Self
pub fn function<Params: TypedMultiValue, Response: TypedMultiValue>( params: Vec<(String, String)>, returns: Vec<String>, ) -> Self
create a type that is a function. i.e. fun(self): number
Trait Implementations§
Source§impl<T: Into<Type>> BitOr<T> for Type
Allows to union types
impl<T: Into<Type>> BitOr<T> for Type
Allows to union types
§Example
use mlua_extras::typed::Type;
Type::string() | Type::nil();Source§impl<T: IntoLuaTypeLiteral> From<T> for Type
impl<T: IntoLuaTypeLiteral> From<T> for Type
Source§impl From<TypedClassBuilder> for Type
impl From<TypedClassBuilder> for Type
Source§fn from(value: TypedClassBuilder) -> Self
fn from(value: TypedClassBuilder) -> Self
Source§impl Ord for Type
impl Ord for Type
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Type
impl PartialOrd for Type
impl Eq for Type
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 UnsafeUnpin for Type
impl UnwindSafe for Type
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more