psmatcher 0.1.10

A pub/sub matcher algorithm implementation
Documentation
// Copyright (c) Subzero Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//! # PSMatcher
//!
//! A pub/sub matcher algorithm implementation that efficiently matches events against subscriptions.
//! The algorithm pre-processes subscriptions into a matching tree for optimized event matching.
//!
//! ## Overview
//!
//! This crate provides a pub/sub matching system where:
//! - Subscriptions are conjunctions of elementary predicates
//! - Events must have at least one string attribute called "topic"
//! - The matching tree is built during pre-processing for efficient matching
//!
//! ## Example
//!
//! ```rust
//! use psmatcher::{Matcher, Subscription, ElementaryPredicate, ElementaryTest};
//! use psmatcher::event_types::{DefaultEvent, AttributeValue};
//!
//! // Create a matcher
//! let mut matcher = Matcher::new();
//!
//! // Create a subscription for weather updates in San Francisco
//! let subscription = Subscription::new("weather-sf")
//!     .with_predicate(ElementaryPredicate::new(
//!         ElementaryTest::Equals {
//!             attribute: "topic".to_string(),
//!             value: AttributeValue::String("weather".to_string()),
//!         },
//!         false,
//!     ))
//!     .with_predicate(ElementaryPredicate::new(
//!         ElementaryTest::Equals {
//!             attribute: "city".to_string(),
//!             value: AttributeValue::String("San Francisco".to_string()),
//!         },
//!         false,
//!     ));
//!
//! // Add the subscription to the matcher
//! matcher.add_subscription(subscription);
//!
//! // Create a subscription using regex pattern matching
//! let regex_subscription = Subscription::new("california-cities")
//!     .with_predicate(ElementaryPredicate::new(
//!         ElementaryTest::regex("topic".to_string(), "weather|forecast").unwrap(),
//!         false,
//!     ))
//!     .with_predicate(ElementaryPredicate::new(
//!         ElementaryTest::regex("city".to_string(), "San (Francisco|Jose|Diego)").unwrap(),
//!         false,
//!     ));
//!
//! // Add the regex subscription to the matcher
//! matcher.add_subscription(regex_subscription);
//!
//! // Create an event
//! let event = DefaultEvent::new("weather")
//!     .with_attribute("city", AttributeValue::String("San Francisco".to_string()))
//!     .with_attribute("temperature", AttributeValue::Float(72.5));
//!
//! // Match the event against subscriptions
//! let matches = matcher.match_event(&event).unwrap();
//!
//! // Check if our subscriptions matched
//! assert!(matches.contains("weather-sf"));
//! assert!(matches.contains("california-cities"));
//! ```
//!
//! For more examples and detailed documentation, see the [README](readme) module.

mod error;
mod event;
mod matcher;
mod predicate;
pub mod readme;
mod subscription;
mod tree;

pub use error::MatcherError;
pub use event::TOPIC_STR;
pub use matcher::Matcher;
pub use predicate::{ElementaryPredicate, ElementaryTest};
pub use subscription::Subscription;
pub use tree::MatchingTree;

// Re-export event types for convenience
pub mod event_types {
    pub use crate::event::{AttributeMap, AttributeValue, DefaultEvent};
}

// Re-export traits for convenience
pub mod traits {
    pub use crate::event::{
        serialization::bincode::{BincodeDeserializable, BincodeSerializable},
        Event,
    };
}

// In test context export helpers
pub mod helpers {
    pub use crate::event::helpers::{
        bool_attr, float_attr, int_attr, list_attr, map_attr, string_attr,
    };
}

// Re-export the readme module for documentation purposes
#[doc(hidden)]
pub use readme::_readme_doc;