pub struct DefinitionBuilder {
pub entries: Vec<Entry>,
pub queued_params: Vec<(String, String)>,
pub queued_returns: Vec<String>,
pub queued_doc: Option<String>,
}Expand description
Builder for definition entries
Fields§
§entries: Vec<Entry>§queued_params: Vec<(String, String)>§queued_returns: Vec<String>§queued_doc: Option<String>Implementations§
Source§impl DefinitionBuilder
impl DefinitionBuilder
Sourcepub fn document(self, doc: impl Display) -> Self
pub fn document(self, doc: impl Display) -> Self
Queue a doc comment for the next function call or value definition
Sourcepub fn param(self, name: impl Display, doc: impl Display) -> Self
pub fn param(self, name: impl Display, doc: impl Display) -> Self
Queue a param for the next function call
Sourcepub fn function<Params, Returns>(
self,
name: impl Display,
_: impl IntoTypedFunction<Params, Returns>,
) -> Selfwhere
Params: TypedMultiValue,
Returns: TypedMultiValue,
pub fn function<Params, Returns>(
self,
name: impl Display,
_: impl IntoTypedFunction<Params, Returns>,
) -> Selfwhere
Params: TypedMultiValue,
Returns: TypedMultiValue,
Register a definition entry that is a function type
Sourcepub fn register_as(
self,
name: impl Into<Cow<'static, str>>,
ty: impl Into<Type>,
) -> Self
pub fn register_as( self, name: impl Into<Cow<'static, str>>, ty: impl Into<Type>, ) -> Self
Register a already built type.
Sourcepub fn value<T: Typed>(self, name: impl Display) -> Self
pub fn value<T: Typed>(self, name: impl Display) -> Self
Register a value that is available
This can be a table, union/enum, literal, or any other value and it will be typed with the given type
§Example
use mlua_extras::{typed::{generator::{Definitions, Definition}, TypedUserData, TypedDataFields}, Typed, UserData};
#[derive(UserData, Typed)]
struct Example {
color: String
}
impl TypedUserData for Example {
fn add_documentation<F: mlua_extras::typed::TypedDataDocumentation<Self>>(docs: &mut F) {
docs.add("This is an example");
}
fn add_fields<F: TypedDataFields<Self>>(fields: &mut F) {
fields
.document("Example field")
.add_field_method_get_set(
"color",
|_lua, this| Ok(this.color.clone()),
|_lua, this, clr: String| {
this.color = clr;
Ok(())
},
);
}
}
Definitions::start()
.define("init", Definition::start()
.register::<Example>("Example")
.value::<Example>("example")
)
.finish();--- init.d.lua
--- @meta
--- This is an example
--- @class Example
--- Example field
--- @field color string
--- The example module
--- @type Example
example = nilSourcepub fn finish(self) -> Definition
pub fn finish(self) -> Definition
Finish the definition
Trait Implementations§
Source§impl Clone for DefinitionBuilder
impl Clone for DefinitionBuilder
Source§fn clone(&self) -> DefinitionBuilder
fn clone(&self) -> DefinitionBuilder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DefinitionBuilder
impl Debug for DefinitionBuilder
Source§impl Default for DefinitionBuilder
impl Default for DefinitionBuilder
Source§fn default() -> DefinitionBuilder
fn default() -> DefinitionBuilder
Returns the “default value” for a type. Read more
Source§impl From<DefinitionBuilder> for Definition
impl From<DefinitionBuilder> for Definition
Source§fn from(value: DefinitionBuilder) -> Self
fn from(value: DefinitionBuilder) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for DefinitionBuilder
impl RefUnwindSafe for DefinitionBuilder
impl Send for DefinitionBuilder
impl Sync for DefinitionBuilder
impl Unpin for DefinitionBuilder
impl UnsafeUnpin for DefinitionBuilder
impl UnwindSafe for DefinitionBuilder
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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