Expand description
Standard functions for the interpreter, and the tools to define new native functions.
§Defining native functions
There are several ways to define new native functions:
- Implement
NativeFnmanually. This is the most versatile approach, but it can be overly verbose. - Use
FnWrapperor thewrapfunction. This allows specifying arguments / output with custom types (such asboolor aNumber), but does not work for non-'statictypes. - Use
wrap_fnorwrap_fn_with_contextmacros. These macros support the same eloquent interface aswrap, and also do not have'staticrequirement for args. As a downside, debugging compile-time errors when using macros can be rather painful.
§Why multiple ways to do the same thing?
In the ideal world, FnWrapper would be used for all cases, since it does not involve
macro magic. Unfortunately, stable Rust currently does not provide means to describe
lifetime restrictions on args / return type of wrapped functions in the general case
(this requires generic associated types). As such, the (implicit) 'static requirement
is a temporary measure, and macros fill the gaps in their usual clunky manner.
Structs§
- Array
- Function generating an array by mapping its indexes.
- Assert
- Assertion function.
- Assert
Eq - Equality assertion function.
- Dbg
- Acts similarly to the
dbg!macro, outputting the argument(s) to stderr and returning them. If a single argument is provided, it’s returned as-is; otherwise, the arguments are wrapped into a tuple. - Filter
- Filter function that evaluates the provided function on each item of the tuple and retains
only elements for which the function returned
true. - FnWrapper
- Wrapper of a function containing information about its arguments.
- Fold
- Reduce (aka fold) function that reduces the provided tuple to a single value.
- From
Value Error - Error raised when a value cannot be converted to the expected type when using
FnWrapper. - If
iffunction that eagerly evaluates “if” / “else” terms.- Len
- Function returning array / object length.
- Loop
- Loop function that evaluates the provided closure one or more times.
- Map
- Map function that evaluates the provided function on each item of the tuple.
- Merge
- Function that merges two tuples.
- Push
- Function that appends a value onto a tuple.
- While
- Loop function that evaluates the provided closure while a certain condition is true. Returns the loop state afterwards.
Enums§
- Compare
- Comparator functions on two primitive arguments. All functions use
Arithmeticto determine ordering between the args. - Error
Output - Generic error output encompassing all error types supported by wrapped functions.
- From
Value Error Kind - Error kinds for
FromValueError. - From
Value Error Location - Element of the
FromValueErrorlocation.
Traits§
- Into
Eval Result - Converts type into
Valueor an error. This is used to convert the return type of wrapped functions to the result expected byNativeFn. - TryFrom
Value - Fallible conversion from
Valueto a function argument.
Functions§
- wrap
- Wraps a function enriching it with the information about its arguments.
This is a slightly shorter way to create wrappers compared to calling
FnWrapper::new().
Type Aliases§
- Binary
- Binary function wrapper.
- Quaternary
- Quaternary function wrapper.
- Ternary
- Ternary function wrapper.
- Unary
- Unary function wrapper.