Shared Rust kernels

catalogue/error_fallback

All modules · quoted at commit 9e1884369a67 of DnaCalc/DnaCalc. Comments are the source's own.

fallback_selected · 28 lines · calc-func/src/catalogue/error_fallback.rs on GitHub
/// The kernel both entries share; `catches` says which errors select the fallback.
fn fallback_selected(
    id: FunctionId,
    arguments: &mut LazyArguments<'_>,
    services: &mut EvalServices<'_>,
    catches: fn(WorksheetErrorCode) -> bool,
) -> Result<CalcValue, FunctionFault> {
    let site = Site::new(id, services);
    let value = arguments.argument(0)?;
    if not_scalar(&value) {
        return Site::finish(Err(site.not_modelled(Some(0))));
    }
    let chosen = match value.core_ref() {
        CoreRef::Error(code) if value.callable_value().is_none() && catches(code) => {
            let fallback = arguments.argument(1)?;
            if not_scalar(&fallback) {
                return Site::finish(Err(site.not_modelled(Some(1))));
            }
            fallback
        }
        _ => value,
    };
    Ok(if chosen.is_missing() {
        CalcValue::empty()
    } else {
        chosen
    })
}

Used by 2 functions.

not_scalar · 5 lines · calc-func/src/catalogue/error_fallback.rs on GitHub
/// Arrays need the evaluator's lifting route. A callable is one value and keeps
/// its identity through fallback selection (fn5 selection005/006).
fn not_scalar(value: &CalcValue) -> bool {
    value.callable_value().is_none() && matches!(value.core_ref(), CoreRef::Array(_))
}

Used by 2 functions.