1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
use fehler::{throw, throws};
use mexprp::{Answer, Context, Expression};

use crate::errors::{self, Error};

#[throws]
pub fn calculate_expression_one_value_result(
    context: &Context<f64>,
    expression: &Expression<f64>,
) -> f64 {
    match expression.eval_ctx(context)? {
        Answer::Single(value) => value,
        _ => throw!(errors::EquationWithMultipleResult {
            equation: expression.string.clone()
        }
        .build()),
    }
}