reactive_graph_std_string/behaviour/entity/string_gate/
function.rs1use std::sync::Arc;
2use std::sync::LazyLock;
3
4use reactive_graph_behaviour_model_impl::entity::EntityBehaviourFactoryCreator;
5use reactive_graph_behaviour_model_impl::entity::EntityBehaviourFunctions;
6use reactive_graph_behaviour_model_impl::entity::EntityBehaviourFunctionsStorage;
7use voca_rs::chop;
8
9use crate::behaviour::entity::string_gate::StringGateFactory;
10use reactive_graph_std_string_model::NAMESPACE_STRING;
11
12pub type StringGateFunction = fn(String, String) -> String;
13
14pub const FN_CHOP_AFTER: StringGateFunction = |lhs, rhs| chop::after(lhs.as_str(), rhs.as_str());
15pub const FN_CHOP_AFTER_LAST: StringGateFunction = |lhs, rhs| chop::after_last(lhs.as_str(), rhs.as_str());
16pub const FN_CONCAT: StringGateFunction = |lhs, rhs| format!("{}{}", lhs, rhs);
17pub const FN_BEFORE: StringGateFunction = |lhs, rhs| chop::before(lhs.as_str(), rhs.as_str());
18pub const FN_BEFORE_LAST: StringGateFunction = |lhs, rhs| chop::before_last(lhs.as_str(), rhs.as_str());
19pub const FN_REMOVE_PREFIX: StringGateFunction = |lhs, rhs| chop::removeprefix(lhs.as_str(), rhs.as_str());
20pub const FN_REMOVE_SUFFIX: StringGateFunction = |lhs, rhs| chop::removesuffix(lhs.as_str(), rhs.as_str());
21
22const FACTORY_CREATOR: EntityBehaviourFactoryCreator<StringGateFunction> = |ty, f| Arc::new(StringGateFactory::new(ty.clone(), f));
23
24pub static STRING_GATES: EntityBehaviourFunctionsStorage<StringGateFunction> = LazyLock::new(|| {
25 EntityBehaviourFunctions::<StringGateFunction>::with_namespace(NAMESPACE_STRING, FACTORY_CREATOR)
26 .behaviour("chop_after", FN_CHOP_AFTER)
27 .behaviour("chop_after_last", FN_CHOP_AFTER_LAST)
28 .behaviour("concat", FN_CONCAT)
29 .behaviour("chop_before", FN_BEFORE)
30 .behaviour("chop_before_last", FN_BEFORE_LAST)
31 .behaviour("chop_remove_prefix", FN_REMOVE_PREFIX)
32 .behaviour("chop_remove_suffix", FN_REMOVE_SUFFIX)
33 .get()
34});