mirror of
https://github.com/ivabus/feval
synced 2024-12-05 05:05:07 +03:00
Initial commit
This commit is contained in:
commit
365be9f72f
7 changed files with 72 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
16
Cargo.lock
generated
Normal file
16
Cargo.lock
generated
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "evalexpr"
|
||||||
|
version = "8.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "aacfb566035f8cd02f6ec9247c242f3f9904a0b288ea383abcf4e95df6436a34"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "feval"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"evalexpr",
|
||||||
|
]
|
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
name = "feval"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
description = "clt for fast evaluations"
|
||||||
|
readme = "README.md"
|
||||||
|
repository = "https://github.com/ivabus/feval"
|
||||||
|
license = "MIT"
|
||||||
|
authors = ["Ivan ivabus Bushchik"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
evalexpr = "8.1.0"
|
7
LICENSE
Normal file
7
LICENSE
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Copyright 2023 Ivan Bushchik
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
5
README.md
Normal file
5
README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# fEval
|
||||||
|
|
||||||
|
> Fast EVALuator
|
||||||
|
|
||||||
|
Simple command line tool, that
|
21
src/main.rs
Normal file
21
src/main.rs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
use evalexpr;
|
||||||
|
use std::env::args;
|
||||||
|
mod tasks;
|
||||||
|
use crate::tasks::tasks::all;
|
||||||
|
|
||||||
|
fn help() {
|
||||||
|
println!(r#"feval: evaluate expressions
|
||||||
|
usage: provide exactly one argument (with expression)
|
||||||
|
example: feval "math::sin(30 * math::pi / 180)""#);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args: Vec<String> = args().collect();
|
||||||
|
if args.len() != 2 {
|
||||||
|
println!("Too many args.");
|
||||||
|
help();
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let expr = all(args[1].clone());
|
||||||
|
println!("{}", evalexpr::eval(&expr).unwrap())
|
||||||
|
}
|
10
src/tasks.rs
Normal file
10
src/tasks.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
pub mod tasks {
|
||||||
|
use std::f64::consts;
|
||||||
|
|
||||||
|
pub fn all(expr: String) -> String {
|
||||||
|
convert_constants(expr)
|
||||||
|
}
|
||||||
|
fn convert_constants(expr: String) -> String {
|
||||||
|
expr.replace("math::pi", &consts::PI.to_string()).replace("math::e", &consts::E.to_string())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue