/calculator

Calculator is a library which support calculates the value of string.

Primary LanguageRustApache License 2.0Apache-2.0

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())
    }
}

Inspired