use crate::Result;
pub trait Function<N> {
fn name(&self) -> &str;
fn call(&self, args: &[N]) -> Result<N>;
fn aliases(&self) -> Option<&[&str]> {
None
}
#[cfg(feature="docs")]
fn description(&self) -> Option<&str> {
None
}
}
pub trait BinaryFunction<N> {
fn name(&self) -> &str;
fn aliases(&self) -> Option<&[&str]> {
None
}
fn precedence(&self) -> Precedence;
fn associativity(&self) -> Associativity;
fn call(&self, left: N, right: N) -> Result<N>;
#[cfg(feature="docs")]
fn description(&self) -> Option<&str> {
None
}
}
pub trait UnaryFunction<N> {
fn name(&self) -> &str;
fn aliases(&self) -> Option<&[&str]> {
None
}
fn notation(&self) -> Notation;
fn call(&self, value: N) -> Result<N>;
#[cfg(feature="docs")]
fn description(&self) -> Option<&str> {
None
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Associativity {
Left,
Right,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Notation {
Prefix,
Postfix,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct Precedence(pub u32);
impl Precedence {
pub const VERY_LOW: Precedence = Precedence::from(0);
pub const LOW: Precedence = Precedence::from(1);
pub const MEDIUM: Precedence = Precedence::from(2);
pub const HIGH: Precedence = Precedence::from(3);
pub const VERY_HIGH: Precedence = Precedence::from(4);
#[inline]
pub const fn from(value: u32) -> Self {
Precedence(value)
}
}
impl From<u32> for Precedence {
#[inline]
fn from(value: u32) -> Self {
Precedence(value)
}
}