pub struct SymTable { /* private fields */ }Expand description
Symbol table containing constants and functions.
The table stores mathematical constants like pi and functions like sin.
Symbol lookups are case-insensitive.
§Examples
use expr_solver::SymTable;
use rust_decimal_macros::dec;
let mut table = SymTable::stdlib();
table.add_const("x", dec!(42)).unwrap();Implementations§
Source§impl SymTable
impl SymTable
Sourcepub fn stdlib() -> Self
pub fn stdlib() -> Self
Creates a symbol table with the standard library.
§Constants
pi- π (3.14159…)e- Euler’s number (2.71828…)tau- 2π (6.28318…)ln2- Natural logarithm of 2ln10- Natural logarithm of 10sqrt2- Square root of 2
§Fixed arity functions
sin(x)- Sinecos(x)- Cosinetan(x)- Tangentasin(x)- Arcsineacos(x)- Arccosineatan(x)- Arctangentatan2(y, x)- Two-argument arctangentsinh(x)- Hyperbolic sinecosh(x)- Hyperbolic cosinetanh(x)- Hyperbolic tangentsqrt(x)- Square rootcbrt(x)- Cube rootpow(x, y)- x raised to power ylog(x)- Natural logarithmlog2(x)- Base-2 logarithmlog10(x)- Base-10 logarithmexp(x)- e raised to power xexp2(x)- 2 raised to power xabs(x)- Absolute valuesign(x)- Sign function (-1, 0, or 1)floor(x)- Floor functionceil(x)- Ceiling functionround(x)- Round to nearest integertrunc(x)- Truncate to integerfract(x)- Fractional partmod(x, y)- Remainder of x/yhypot(x, y)- Euclidean distance sqrt(x²+y²)clamp(x, min, max)- Constrain value between bounds
§Variadic functions
min(x, ...)- Minimum valuemax(x, ...)- Maximum valuesum(x, ...)- Sum of valuesavg(x, ...)- Average of values
Sourcepub fn add_const<S: Into<Cow<'static, str>>>(
&mut self,
name: S,
value: Decimal,
) -> Result<&mut Self, SymbolError>
pub fn add_const<S: Into<Cow<'static, str>>>( &mut self, name: S, value: Decimal, ) -> Result<&mut Self, SymbolError>
Adds a constant to the table.
Returns an error if a symbol with the same name already exists.
Sourcepub fn add_func<S: Into<Cow<'static, str>>>(
&mut self,
name: S,
args: usize,
variadic: bool,
callback: fn(&[Decimal]) -> Result<Decimal, FuncError>,
) -> Result<&mut Self, SymbolError>
pub fn add_func<S: Into<Cow<'static, str>>>( &mut self, name: S, args: usize, variadic: bool, callback: fn(&[Decimal]) -> Result<Decimal, FuncError>, ) -> Result<&mut Self, SymbolError>
Adds a function to the table.
§Parameters
name: Function nameargs: Minimum number of argumentsvariadic: Whether the function accepts additional argumentscallback: Function implementation
Returns an error if a symbol with the same name already exists.
Sourcepub fn get_with_index(&self, name: &str) -> Option<(usize, &Symbol)>
pub fn get_with_index(&self, name: &str) -> Option<(usize, &Symbol)>
Looks up a symbol by name and returns its index and reference (case-insensitive).
Sourcepub fn get_by_index(&self, index: usize) -> Option<&Symbol>
pub fn get_by_index(&self, index: usize) -> Option<&Symbol>
Returns a symbol by index.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SymTable
impl RefUnwindSafe for SymTable
impl Send for SymTable
impl Sync for SymTable
impl Unpin for SymTable
impl UnwindSafe for SymTable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more