rune::module

Struct ModuleRawFunctionBuilder

Source
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>

Source

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()?;
Source

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>()?;
Source

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.

Auto Trait Implementations§

§

impl<'a, N> Freeze for ModuleRawFunctionBuilder<'a, N>
where N: Freeze,

§

impl<'a, N> !RefUnwindSafe for ModuleRawFunctionBuilder<'a, N>

§

impl<'a, N> Send for ModuleRawFunctionBuilder<'a, N>
where N: Send,

§

impl<'a, N> Sync for ModuleRawFunctionBuilder<'a, N>
where N: Sync,

§

impl<'a, N> Unpin for ModuleRawFunctionBuilder<'a, N>
where N: Unpin,

§

impl<'a, N> !UnwindSafe for ModuleRawFunctionBuilder<'a, N>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T