#string #value #calculator

calculator-rs

Calculator is a library which support calculates the value of string

3 releases

0.1.2 Nov 9, 2023
0.1.1 Nov 9, 2023
0.1.0 Nov 9, 2023

#895 in Math

Download history 26/week @ 2024-09-02 18/week @ 2024-09-09 6/week @ 2024-09-16 43/week @ 2024-09-23 54/week @ 2024-09-30 33/week @ 2024-10-07 18/week @ 2024-10-14 10/week @ 2024-10-21 1/week @ 2024-10-28 22/week @ 2024-11-04

55 downloads per month

Apache-2.0

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

Inspired

No runtime deps