3 unstable releases

0.2.1 Nov 11, 2023
0.2.0 Sep 10, 2023
0.1.0 Oct 1, 2022

#748 in Math

Download history 8/week @ 2024-06-24 6/week @ 2024-07-08 12/week @ 2024-07-15 35/week @ 2024-07-29 15/week @ 2024-08-26 4/week @ 2024-09-16 50/week @ 2024-09-23 13/week @ 2024-09-30

67 downloads per month
Used in 4 crates (via yash-semantics)

GPL-3.0-or-later

165KB
4.5K SLoC

Yash-arith

yash-arith is a Rust library crate for performing the POSIX shell's arithmetic expansion. This crate is part of yash but can be used independently.

yash-arith at crates.io yash-arith at docs.rs Build status

Usage

Add yash-arith as a dependency in your Cargo.toml.

use std::collections::HashMap;
use yash_arith::{eval, Value};
let mut env = HashMap::new();
env.insert("a".to_owned(), "2".to_owned());
let result = eval("1 + a", &mut env);
assert_eq!(result, Ok(Value::Integer(3)));

License

This crate is distributed under GPLv3.


lib.rs:

This crate implements shell arithmetic expansion.

Arithmetic expansion evaluates an expression that may contain some operators that perform basic maths. The expression is given as a string and parsed like an expression in C. The expression can include variables that interact with the environment.

To evaluate an expression, you call the [eval()] function with a string and an environment.

use std::collections::HashMap;
use yash_arith::{eval, Value};
let mut env = HashMap::new();
env.insert("a".to_owned(), "2".to_owned());
let result = eval("1 + a", &mut env);
assert_eq!(result, Ok(Value::Integer(3)));

Dependencies

~270–720KB
~17K SLoC