reactive_graph_std_string/behaviour/entity/string_string_number_gate/
function.rs

1use 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::count;
8
9use reactive_graph_std_string_model::NAMESPACE_STRING;
10
11use crate::behaviour::entity::string_string_number_gate::StringStringNumberGateFactory;
12
13pub type StringStringNumberFunction = fn(String, String) -> usize;
14
15pub const FN_COUNT_SUBSTRINGS: StringStringNumberFunction = |lhs, rhs| count::count_substrings(lhs.as_str(), rhs.as_str());
16pub const FN_COUNT_UNIQUE_WORDS: StringStringNumberFunction = |lhs, rhs| count::count_unique_words(lhs.as_str(), rhs.as_str());
17pub const FN_COUNT_WORDS: StringStringNumberFunction = |lhs, rhs| count::count_words(lhs.as_str(), rhs.as_str());
18
19const FACTORY_CREATOR: EntityBehaviourFactoryCreator<StringStringNumberFunction> = |ty, f| Arc::new(StringStringNumberGateFactory::new(ty.clone(), f));
20
21pub static STRING_STRING_NUMBER_GATES: EntityBehaviourFunctionsStorage<StringStringNumberFunction> = LazyLock::new(|| {
22    EntityBehaviourFunctions::<StringStringNumberFunction>::with_namespace(NAMESPACE_STRING, FACTORY_CREATOR)
23        .behaviour("count_substrings", FN_COUNT_SUBSTRINGS)
24        .behaviour("count_unique_words", FN_COUNT_UNIQUE_WORDS)
25        .behaviour("count_words", FN_COUNT_WORDS)
26        .get()
27});