moduforge_rules_expression/functions/
mod.rs1pub use crate::functions::date_method::DateMethod;
6pub use crate::functions::defs::FunctionTypecheck;
7pub use crate::functions::deprecated::DeprecatedFunction;
8pub use crate::functions::internal::InternalFunction;
9pub use crate::functions::method::{MethodKind, MethodRegistry};
10pub use crate::functions::registry::FunctionRegistry;
11pub use crate::functions::custom::CustomFunction;
12pub use crate::functions::state_guard::{StateGuard, with_state_async};
13
14use std::fmt::Display;
15use strum_macros::{Display, EnumIter, EnumString, IntoStaticStr};
16
17pub mod arguments; pub mod custom;
19mod date_method; pub mod defs; mod deprecated; pub mod internal; mod method; pub(crate) mod registry; pub mod state_guard; #[derive(Debug, PartialEq, Eq, Clone)]
31pub enum FunctionKind {
32    Internal(InternalFunction),
34    Deprecated(DeprecatedFunction),
36    Closure(ClosureFunction),
38    Custom(CustomFunction),
40}
41
42impl TryFrom<&str> for FunctionKind {
43    type Error = strum::ParseError;
44
45    fn try_from(value: &str) -> Result<Self, Self::Error> {
49        InternalFunction::try_from(value)
50            .map(FunctionKind::Internal)
51            .or_else(|_| {
52                DeprecatedFunction::try_from(value)
53                    .map(FunctionKind::Deprecated)
54            })
55            .or_else(|_| {
56                ClosureFunction::try_from(value).map(FunctionKind::Closure)
57            })
58            .or_else(|_| {
59                CustomFunction::try_from(value).map(FunctionKind::Custom)
60            })
61    }
62}
63
64impl Display for FunctionKind {
65    fn fmt(
66        &self,
67        f: &mut std::fmt::Formatter<'_>,
68    ) -> std::fmt::Result {
69        match self {
70            FunctionKind::Internal(i) => write!(f, "{i}"),
71            FunctionKind::Deprecated(d) => write!(f, "{d}"),
72            FunctionKind::Closure(c) => write!(f, "{c}"),
73            FunctionKind::Custom(c) => write!(f, "{c}"),
74        }
75    }
76}
77
78#[derive(
82    Debug,
83    PartialEq,
84    Eq,
85    Hash,
86    Display,
87    EnumString,
88    EnumIter,
89    IntoStaticStr,
90    Clone,
91    Copy,
92)]
93#[strum(serialize_all = "camelCase")]
94pub enum ClosureFunction {
95    All,
97    None,
99    Some,
101    One,
103    Filter,
105    Map,
107    FlatMap,
109    Count,
111}