rune::module

Struct ModuleFunctionBuilder

Source
pub struct ModuleFunctionBuilder<'a, F, A, N, K> { /* private fields */ }
Expand description

Function builder as returned by Module::function.

This allows for building a function regularly with ModuleFunctionBuilder::build or statically associate the function with a type through ModuleFunctionBuilder::build_associated::<T>.

Implementations§

Source§

impl<'a, F, A, N, K> ModuleFunctionBuilder<'a, F, A, N, K>
where F: Function<A, K>, F::Return: MaybeTypeOf, A: FunctionArgs, K: FunctionKind,

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};

let mut m = Module::with_item(["module"])?;
m.function("floob", || ()).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, Context, Module};

#[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};

#[derive(Any)]
struct Thing;

let mut m = Module::default();
m.ty::<Thing>()?;
m.function("floob", || ()).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, F, A, N, K> Freeze for ModuleFunctionBuilder<'a, F, A, N, K>
where N: Freeze, F: Freeze,

§

impl<'a, F, A, N, K> !RefUnwindSafe for ModuleFunctionBuilder<'a, F, A, N, K>

§

impl<'a, F, A, N, K> Send for ModuleFunctionBuilder<'a, F, A, N, K>
where N: Send, F: Send, A: Send, K: Send,

§

impl<'a, F, A, N, K> Sync for ModuleFunctionBuilder<'a, F, A, N, K>
where N: Sync, F: Sync, A: Sync, K: Sync,

§

impl<'a, F, A, N, K> Unpin for ModuleFunctionBuilder<'a, F, A, N, K>
where N: Unpin, F: Unpin, A: Unpin, K: Unpin,

§

impl<'a, F, A, N, K> !UnwindSafe for ModuleFunctionBuilder<'a, F, A, N, K>

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