Expand description
The native function binding system - Module, NativeFn, and the
IntoNativeFn / FromValue / IntoValue trait machinery.
§How it works
Stdlib functions are plain Rust functions. The IntoNativeFn trait
(implemented by a macro for up to 10 arguments) wraps them into NativeFn
closures that handle arity checking and argument extraction automatically.
Two variants exist:
- Infallible (
IntoNativeFn<(A1, A2, ...)>) - for functions that returnR: IntoValue - Fallible (
IntoNativeFn<(Fallible<(A1, A2, ...)>,)>) - for functions returningResult<R, Error> - Spanned (
IntoNativeFn<(Spanned<(A1, A2, ...)>,)>) - fallible functions that also receive the callSpan
§Example
use rl_lang::interpreter::{evaluator::Evaluator, native::Module};
fn my_fn(_: &mut Evaluator, x: i64, y: i64) -> i64 { x + y }
Module::new("math").with_function("add", my_fn);Macros§
Structs§
- Fallible
- Marker type for fallible native functions (returning
Result<R, Error>). - Module
- A named collection of
NativeFns, optionally containing sub-Modules. - Spanned
- Marker type for spanned fallible native functions (also receiving the call
Span).
Traits§
- From
Value - Converts a
Valueinto a typed Rust value, or returns a runtime error. Implemented fori64,f64,String,bool,char,Vec<T>, andValueitself. - Into
Native Fn - Wraps a typed Rust function into a
NativeFnwith automatic arity checking and argument extraction. Implemented by macro for 0–10 arguments. - Into
Value - Converts a typed Rust value into a
Value. Implemented for()(→Null),i64,f64,String,bool,char,Vec<T>, andValue. - Value
Type - Extracts the static
TypeAnnotationfor a Rust type. Used byIntoValueforVec<T>to set the array’sitems_type.
Type Aliases§
- Native
Fn - A thread-safe, heap-allocated native function callable from rl.