reactive_graph_std_string/behaviour/entity/string_comparison/
function.rs1use crate::behaviour::entity::string_comparison::StringComparisonFactory;
2use reactive_graph_behaviour_model_impl::entity::EntityBehaviourFactoryCreator;
3use reactive_graph_behaviour_model_impl::entity::EntityBehaviourFunctions;
4use reactive_graph_behaviour_model_impl::entity::EntityBehaviourFunctionsStorage;
5use reactive_graph_std_string_model::NAMESPACE_STRING;
6use std::sync::Arc;
7use std::sync::LazyLock;
8
9pub type StringComparisonFunction = fn(String, String) -> bool;
10
11pub const FN_CONTAINS: StringComparisonFunction = |lhs, rhs| lhs.contains(rhs.as_str());
12pub const FN_ENDS_WITH: StringComparisonFunction = |lhs, rhs| lhs.ends_with(rhs.as_str());
13pub const FN_STARTS_WITH: StringComparisonFunction = |lhs, rhs| lhs.starts_with(rhs.as_str());
14
15const FACTORY_CREATOR: EntityBehaviourFactoryCreator<StringComparisonFunction> = |ty, f| Arc::new(StringComparisonFactory::new(ty.clone(), f));
16
17pub static STRING_COMPARISONS: EntityBehaviourFunctionsStorage<StringComparisonFunction> = LazyLock::new(|| {
18 EntityBehaviourFunctions::<StringComparisonFunction>::with_namespace(NAMESPACE_STRING, FACTORY_CREATOR)
19 .behaviour("contains", FN_CONTAINS)
20 .behaviour("ends_with", FN_ENDS_WITH)
21 .behaviour("starts_with", FN_STARTS_WITH)
22 .get()
23});