zen_expression/functions/
mod.rs

1pub use crate::functions::arguments::Arguments;
2pub use crate::functions::deprecated::DeprecatedFunction;
3pub use crate::functions::internal::InternalFunction;
4pub use crate::functions::registry::{FunctionDefinition, FunctionRegistry, FunctionTypecheck};
5use std::fmt::Display;
6use strum_macros::{Display, EnumIter, EnumString, IntoStaticStr};
7
8pub(crate) mod arguments;
9pub(crate) mod defs;
10mod deprecated;
11pub(crate) mod internal;
12pub(crate) mod registry;
13
14#[derive(Debug, PartialEq, Eq, Clone)]
15pub enum FunctionKind {
16    Internal(InternalFunction),
17    Deprecated(DeprecatedFunction),
18    Closure(ClosureFunction),
19}
20
21impl TryFrom<&str> for FunctionKind {
22    type Error = strum::ParseError;
23
24    fn try_from(value: &str) -> Result<Self, Self::Error> {
25        InternalFunction::try_from(value)
26            .map(FunctionKind::Internal)
27            .or_else(|_| DeprecatedFunction::try_from(value).map(FunctionKind::Deprecated))
28            .or_else(|_| ClosureFunction::try_from(value).map(FunctionKind::Closure))
29    }
30}
31
32impl Display for FunctionKind {
33    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34        match self {
35            FunctionKind::Internal(i) => write!(f, "{i}"),
36            FunctionKind::Deprecated(d) => write!(f, "{d}"),
37            FunctionKind::Closure(c) => write!(f, "{c}"),
38        }
39    }
40}
41
42#[derive(Debug, PartialEq, Eq, Hash, Display, EnumString, EnumIter, IntoStaticStr, Clone, Copy)]
43#[strum(serialize_all = "camelCase")]
44pub enum ClosureFunction {
45    All,
46    None,
47    Some,
48    One,
49    Filter,
50    Map,
51    FlatMap,
52    Count,
53}