ripin 0.1.2

A library that handle Reverse Polish notated expressions, compiles, and evaluate them.
Documentation
  • Coverage
  • 70.45%
    62 out of 88 items documented2 out of 19 items with examples
  • Size
  • Source code size: 58.85 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 7.94 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 24s Average build duration of successful builds.
  • all releases: 24s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Kerollmops/ripin-rs
    0 1 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Kerollmops

Ripin-rs

Crates.io Documentation Build Status Coverage Status

A library to handle Reverse Polish notated expressions.

Ripin can also evaluate variable expressions and is not limited to string tokens, it can handle any iterator type, the only limit is your imagination. There is examples to understand how to implement your own expression from custom types.

Installation

Ripin is available on crates.io and can be included in your Cargo enabled project like this:

[dependencies]
ripin = "0.1"

Then include it in your code like this:

extern crate ripin;

Examples

Ripin can evaluate Reverse Polish Notated expressions.

use ripin::expression::FloatExpr;

let expr_str = "3 4 + 2 *"; // (3 + 4) * 2
let tokens = expr_str.split_whitespace();

let expr = FloatExpr::<f32>::from_iter(tokens).unwrap();

println!("Expression {:?} gives {:?}", expr_str, expr.evaluate())

It is also possible to use variables in your expressions to make them more "variable".

use std::collections::HashMap;
use ripin::evaluate::VariableFloatExpr;
use ripin::variable::IndexVar;

let mut variables = HashMap::new(); // using a Vec is the same
variables.insert(0, 3.0);
variables.insert(1, 500.0);

let expr_str = "3 $1 + 2 * $0 -"; // (3 + $1) * 2 - $0
let tokens = expr_str.split_whitespace();

let expr = VariableFloatExpr::<f32, IndexVar>::from_iter(tokens).unwrap();

let result = expr.evaluate_with_variables(&variables);

println!("Expression {:?} gives {:?}", expr_str, result); // Ok(1003)