pub fn function<Func, Args, N>(&mut self, name: N, f: Func) -> Result<(), ContextError>
    where
        Func: Function<Args>,
        N: IntoIterator,
        N::Item: IntoComponent,
    {
        let name = Item::with_item(name);

        if self.functions.contains_key(&name) {
            return Err(ContextError::ConflictingFunctionName { name });
        }

        self.functions.insert(
            name,
            ModuleFn {
                handler: Arc::new(move |stack, args| f.fn_call(stack, args)),
                args: Some(Func::args()),
            },
        );

        Ok(())
    }
/// Register a function that cannot error internally.
///
/// # Examples
///
/// ```rust
/// fn add_ten(value: i64) -> i64 {
///     value + 10
/// }
///
/// # fn main() -> runestick::Result<()> {
/// let mut module = runestick::Module::default();
///
/// module.function(&["add_ten"], add_ten)?;
/// module.function(&["empty"], || Ok::<_, runestick::Error>(()))?;
/// module.function(&["string"], |a: String| Ok::<_, runestick::Error>(()))?;
/// module.function(&["optional"], |a: Option<String>| Ok::<_, runestick::Error>(()))?;
/// # Ok(()) }
/// ```
Register a function that cannot error internally.
Register a function that cannot error internally .
pub fn function<Func, Args, N>(&mut self, name: N, f: Func) -> Result<(), ContextError>
    where
        Func: Function<Args>,
        N: IntoIterator,
        N::Item: IntoComponent,
    {
        let name = Item::with_item(name);
        if self.functions.contains_key(&name) {
            return Err(ContextError::ConflictingFunctionName { name });
        }
        self.functions.insert(
            name,
            ModuleFn {
                handler: Arc::new(move |stack, args| f.fn_call(stack, args)),
                args: Some(Func::args()),
            },
        );
        Ok(())
    }
pub fn function < Func , Args , N > ( & mut self , name : N , f : Func ) -> Result < ( ) , ContextError > where Func : Function < Args > , N : IntoIterator , N :: Item : IntoComponent , { let name = Item :: with_item ( name ) ; if self . functions . contains_key ( & name ) { return Err ( ContextError :: ConflictingFunctionName { name } ) ; } self . functions . insert ( name , ModuleFn { handler : Arc :: new ( move | stack , args | f . fn_call ( stack , args ) ) , args : Some ( Func :: args ( ) ) , } , ) ; Ok ( ( ) ) }
Register a function that cannot error internally.
Register a function that cannot error internally .
&mut self
name
N
f
Func
&mut self
name
N
f
Func
examples
None
fn main() -> runestick::result<()> {
let mut module = runestick::Module::default().


let mut module = runestick :: Module :: default () .
ok(()) }
None