use crate::compile::ContextError;
use crate::function::{Function, FunctionKind};
use crate::function_meta::{FunctionArgs, FunctionBuilder, ToInstance};
use crate::item::IntoComponent;
use crate::module::ItemFnMut;
use crate::runtime::{MaybeTypeOf, TypeInfo, TypeOf};
use crate::Hash;
use super::Module;
#[must_use = "Must call one of the build functions, like `build` or `build_associated`"]
pub struct ModuleFunctionBuilder<'a, F, A, N, K> {
pub(super) module: &'a mut Module,
pub(super) inner: FunctionBuilder<N, F, A, K>,
}
impl<'a, F, A, N, K> ModuleFunctionBuilder<'a, F, A, N, K>
where
F: Function<A, K, Return: MaybeTypeOf>,
A: FunctionArgs,
K: FunctionKind,
{
#[inline]
pub fn build(self) -> Result<ItemFnMut<'a>, ContextError>
where
N: IntoComponent,
{
let meta = self.inner.build()?;
self.module.function_from_meta_kind(meta)
}
#[inline]
pub fn build_associated<T>(self) -> Result<ItemFnMut<'a>, ContextError>
where
N: ToInstance,
T: TypeOf,
{
let meta = self.inner.build_associated::<T>()?;
self.module.function_from_meta_kind(meta)
}
#[inline]
pub fn build_associated_with(
self,
container: Hash,
container_type_info: TypeInfo,
) -> Result<ItemFnMut<'a>, ContextError>
where
N: ToInstance,
{
let meta = self
.inner
.build_associated_with(container, container_type_info)?;
self.module.function_from_meta_kind(meta)
}
}