feat: create lib.rs API
This commit is contained in:
parent
ae9e6604e8
commit
d2368adc8f
3 changed files with 12 additions and 2 deletions
|
|
@ -79,7 +79,7 @@ pub fn get_significant_digits(n: &Float) -> usize {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn eval(s: &str) -> Float {
|
fn eval(s: &str) -> Float {
|
||||||
Nodes::from_str(s).unwrap().evaluate()
|
crate::nodes::eval(s).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
4
src/lib.rs
Normal file
4
src/lib.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
pub mod formatting;
|
||||||
|
pub mod nodes;
|
||||||
|
|
||||||
|
pub use nodes::eval;
|
||||||
|
|
@ -5,10 +5,16 @@
|
||||||
use rug::Float;
|
use rug::Float;
|
||||||
|
|
||||||
mod evaluate;
|
mod evaluate;
|
||||||
mod from_str;
|
pub mod from_str;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
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;
|
pub const PREC: u32 = 512;
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq)]
|
#[derive(Debug, Default, Clone, PartialEq)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue