Skip to main content

explain

Function explain 

Source
pub fn explain(tariff: &Versioned<'_>) -> Verdict<String, Warning>
Expand description

Explain the given tariff in human language, returning the explanation as Markdown.

The tariff is parsed into the normalized v2.2.1 form first, so a v2.1.1 tariff is explained as its v2.2.1 equivalent. Warnings raised while parsing are returned alongside the explanation; a hard parse failure returns an ErrorSet instead.

ยงExample


let json = json::parse_object(TARIFF_JSON).unwrap();
let version = tariff::infer_version(json);
let tariff = tariff::build_versioned(version.certain_or_none().unwrap()).ignore_warnings();

let Ok(explanation) = tariff::explain(&tariff) else {
    return Err("The tariff could not be parsed well enough to explain.".into());
};

println!("{}", explanation.ignore_warnings());