Add some documentation, and clean up EvalError a bit.

This commit is contained in:
2023-04-27 21:06:03 -07:00
parent 3615d19485
commit c3b394d2c9
3 changed files with 72 additions and 15 deletions

View File

@@ -68,7 +68,11 @@ impl Value {
/// Calculate the result of running the given primitive on the given arguments.
///
/// This can cause errors in a whole mess of ways, so be careful about your
/// inputs.
/// inputs. For example, addition only works when the two values have the exact
/// same type, so expect an error if you try to do so. In addition, this
/// implementation catches and raises an error on overflow or underflow, so
/// its worth being careful to make sure that your inputs won't cause either
/// condition.
pub fn calculate(operation: &str, values: Vec<Value>) -> Result<Value, PrimOpError> {
if values.len() == 2 {
Value::binary_op(operation, &values[0], &values[1])