pub struct ModuleRawFunctionBuilder<'a, N> { /* private fields */ }
Expand description
Raw function builder as returned by Module::raw_function
.
This allows for building a function regularly with
ModuleRawFunctionBuilder::build
or statically associate the function
with a type through ModuleRawFunctionBuilder::build_associated::<T>
.
Implementations§
Source§impl<'a, N> ModuleRawFunctionBuilder<'a, N>
impl<'a, N> ModuleRawFunctionBuilder<'a, N>
Sourcepub fn build(self) -> Result<ItemFnMut<'a>, ContextError>where
N: IntoComponent,
pub fn build(self) -> Result<ItemFnMut<'a>, ContextError>where
N: IntoComponent,
Construct a regular function.
This register the function as a free function in the module it’s associated with, who’s full name is the name of the module extended by the name of the function.
§Examples
use rune::{Any, Module};
use rune::runtime::VmResult;
let mut m = Module::with_item(["module"])?;
m.raw_function("floob", |_, _, _, _| VmResult::Ok(())).build()?;
Sourcepub fn build_associated<T>(self) -> Result<ItemFnMut<'a>, ContextError>where
N: ToInstance,
T: TypeOf,
pub fn build_associated<T>(self) -> Result<ItemFnMut<'a>, ContextError>where
N: ToInstance,
T: TypeOf,
Construct a function that is associated with T
.
This registers the function as an assocaited function, which can only be
used through the type T
.
§Errors
This function call will cause an error in Context::install
if the
type we’re associating it with has not been registered.
use rune::{Any, Module, Context};
#[derive(Any)]
struct Thing;
let mut m = Module::default();
m.function("floob", || ()).build_associated::<Thing>()?;
let mut c = Context::default();
assert!(c.install(m).is_err());
§Examples
use rune::{Any, Module};
use rune::runtime::VmResult;
#[derive(Any)]
struct Thing;
let mut m = Module::default();
m.ty::<Thing>()?;
m.raw_function("floob", |_, _, _, _| VmResult::Ok(())).build_associated::<Thing>()?;
Sourcepub fn build_associated_with(
self,
container: Hash,
container_type_info: TypeInfo,
) -> Result<ItemFnMut<'a>, ContextError>where
N: ToInstance,
pub fn build_associated_with(
self,
container: Hash,
container_type_info: TypeInfo,
) -> Result<ItemFnMut<'a>, ContextError>where
N: ToInstance,
Construct a function that is associated with a custom dynamically specified container.
This registers the function as an assocaited function, which can only be used through the specified type.
Hash
and TypeInfo
are usually constructed through the TypeOf
trait. But that requires access to a static type, for which you should
use build_associated
instead.
§Errors
The function call will error if the specified type is not already registered in the module.