feat: create lib.rs API

This commit is contained in:
electria 2026-09-30 18:25:46 -07:00
commit d2368adc8f
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
3 changed files with 12 additions and 2 deletions

View file

@ -79,7 +79,7 @@ pub fn get_significant_digits(n: &Float) -> usize {
#[cfg(test)]
fn eval(s: &str) -> Float {
Nodes::from_str(s).unwrap().evaluate()
crate::nodes::eval(s).unwrap()
}
#[test]

4
src/lib.rs Normal file
View file

@ -0,0 +1,4 @@
pub mod formatting;
pub mod nodes;
pub use nodes::eval;

View file

@ -5,10 +5,16 @@
use rug::Float;
mod evaluate;
mod from_str;
pub mod from_str;
#[cfg(test)]
mod tests;
/// helper function to parse to Nodes and immediately evaluate
pub fn eval(s: &str) -> Result<rug::Float, from_str::Error> {
use std::str::FromStr;
Nodes::from_str(s).map(|nodes| nodes.evaluate())
}
pub const PREC: u32 = 512;
#[derive(Debug, Default, Clone, PartialEq)]