[−][src]Module arithmetic_eval::fns
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
| Assert | Assertion function. |
| AssertEq | Equality assertion function. |
| Dbg | stdActs similarly to the |
| Filter | Filter function that evaluates the provided function on each item of the tuple and retains
only elements for which the function returned |
| FnWrapper | Wrapper of a function containing information about its arguments. |
| Fold | Reduce (aka fold) function that reduces the provided tuple to a single value. |
| FromValueError | Error raised when a value cannot be converted to the expected type when using
|
| If |
|
| 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 number arguments. All functions use |
| ErrorOutput | Generic error output encompassing all error types supported by wrapped functions. |
| FromValueErrorKind | Error kinds for |
| FromValueErrorLocation | Element of the |
Traits
| IntoEvalResult | Converts type into |
| TryFromValue | Fallible conversion from |
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 |
Type Definitions
| Binary | Binary function wrapper. |
| Quaternary | Quaternary function wrapper. |
| Ternary | Ternary function wrapper. |
| Unary | Unary function wrapper. |