3 releases
0.1.2 | Nov 9, 2023 |
---|---|
0.1.1 | Nov 9, 2023 |
0.1.0 | Nov 9, 2023 |
#895 in Math
55 downloads per month
25KB
634 lines
Calculator
Calculator is a library which support calculates the value of string.
[dependencies]
calculator-rs = { version = "*" }
Example
fn main(){
{
let calculator = "1+1".calculate();
assert_eq!(calculator, Ok(Value::Integer(2)))
}
{
let calculator = "1*1".calculate();
assert_eq!(calculator, Ok(Value::Integer(1)))
}
{
let calculator = "2*4".calculate();
assert_eq!(calculator, Ok(Value::Integer(8)))
}
{
let calculator = "4!".calculate();
assert_eq!(calculator, Ok(Value::Integer(24)))
}
{
let calculator = "31%15".calculate();
assert_eq!(calculator, Ok(Value::Integer(1)))
}
{
let calculator = "1*!1".calculate();
assert!(calculator.is_err())
}
}