Struct rink::context::Context
[−]
[src]
pub struct Context { pub dimensions: BTreeSet<Dim>, pub canonicalizations: BTreeMap<String, String>, pub units: BTreeMap<String, Number>, pub quantities: BTreeMap<Unit, String>, pub reverse: BTreeMap<Unit, String>, pub prefixes: Vec<(String, Number)>, pub definitions: BTreeMap<String, Expr>, pub docs: BTreeMap<String, String>, pub categories: BTreeMap<String, String>, pub category_names: BTreeMap<String, String>, pub datepatterns: Vec<Vec<DatePattern>>, pub substances: BTreeMap<String, Substance>, pub substance_symbols: BTreeMap<String, String>, pub temporaries: BTreeMap<String, Number>, pub short_output: bool, pub use_humanize: bool, }
The evaluation context that contains unit definitions.
Fields
dimensions: BTreeSet<Dim>
canonicalizations: BTreeMap<String, String>
units: BTreeMap<String, Number>
quantities: BTreeMap<Unit, String>
reverse: BTreeMap<Unit, String>
prefixes: Vec<(String, Number)>
definitions: BTreeMap<String, Expr>
docs: BTreeMap<String, String>
categories: BTreeMap<String, String>
category_names: BTreeMap<String, String>
datepatterns: Vec<Vec<DatePattern>>
substances: BTreeMap<String, Substance>
substance_symbols: BTreeMap<String, String>
temporaries: BTreeMap<String, Number>
short_output: bool
use_humanize: bool
Methods
impl Context
[src]
fn new() -> Context
Creates a new, empty context
fn load_dates(&mut self, dates: Vec<Vec<DatePattern>>)
fn lookup(&self, name: &str) -> Option<Number>
Given a unit name, returns its value if it exists. Supports SI prefixes, plurals, bare dimensions like length, and quantities.
fn canonicalize(&self, name: &str) -> Option<String>
Given a unit name, try to return a canonical name (expanding aliases and such)
fn describe_unit(&self, value: &Number) -> (bool, String)
Describes a value's unit, gives true if the unit is reciprocal (e.g. you should prefix "1.0 / " or replace "multiply" with "divide" when rendering it).
fn typo_dym<'a>(&'a self, what: &str) -> Option<&'a str>
fn unknown_unit_err(&self, name: &str) -> NotFoundError
impl Context
[src]
fn eval(&self, expr: &Expr) -> Result<Value, QueryError>
Evaluates an expression to compute its value, excluding ->
conversions.
fn eval_unit_name(
&self,
expr: &Expr
) -> Result<(BTreeMap<String, isize>, Num), QueryError>
&self,
expr: &Expr
) -> Result<(BTreeMap<String, isize>, Num), QueryError>
fn show(
&self,
raw: &Number,
bottom: &Number,
bottom_name: BTreeMap<String, isize>,
bottom_const: Num,
base: u8,
digits: Digits
) -> ConversionReply
&self,
raw: &Number,
bottom: &Number,
bottom_name: BTreeMap<String, isize>,
bottom_const: Num,
base: u8,
digits: Digits
) -> ConversionReply
fn eval_outer(&self, expr: &Query) -> Result<QueryReply, QueryError>
Evaluates an expression, include ->
conversions.
impl Context
[src]
impl Context
[src]
fn load(&mut self, defs: Defs)
Takes a parsed definitions.units from
gnu_units::parse()
. Prints if there are errors in the file.