calculator-rs

Crates.iocalculator-rs
lib.rscalculator-rs
version0.1.2
sourcesrc
created_at2023-11-09 13:11:38.112023
updated_at2023-11-09 13:17:05.297704
descriptionCalculator is a library which support calculates the value of string
homepagehttps://github.com/misssonder/calculator
repositoryhttps://github.com/misssonder/calculator
max_upload_size
id1030163
size35,424
(misssonder)

documentation

https://docs.rs/calculator-rs

README

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

Commit count: 5

cargo fmt