// use meval::eval_str; use cpc::{ eval, units::Unit, }; use mlua::prelude::*; use crate::lenses::{ Entry, Cache, Lense }; pub struct Calculator; impl Lense for Calculator { const NAME: &str = "Calculator"; fn get_cache(&self) -> &Cache { &Cache::Stale } fn set_cache(&mut self, _: Cache) {} fn query(_: &Lua, input: String) -> Result, anyhow::Error> { let result = match eval(input.trim(), true, Unit::Celsius, false) { Ok(result) => { format!("{result}") } Err(err) => { return Err(anyhow::anyhow!(err)); }, }; Ok(vec![Entry { message: result, exec: None, }; 1] ) } }