eventuary-core 0.1.0

Core event model and async IO traits for eventuary
Documentation
//! Core event model and async IO traits for the eventuary toolkit.
//!
//! This crate provides the typed event model ([`Event`], [`Payload`], [`Topic`],
//! [`Namespace`], [`OrganizationId`]), serialization helpers ([`SerializedEvent`]),
//! and async IO traits for backends ([`io::Reader`], [`io::Writer`], [`io::Handler`], [`io::Acker`]).
//!
//! Most consumers should depend on the [`eventuary`] umbrella crate and pick
//! backends via Cargo features, instead of using `eventuary-core` directly.
//! Use this crate when you are implementing a new backend or want only the
//! core types without any backend.
//!
//! # Example
//!
//! ```
//! use eventuary_core::{Event, Payload};
//!
//! let event = Event::builder(
//!     "acme",
//!     "/billing",
//!     "invoice.created",
//!     "invoice-123",
//!     Payload::from_json(&serde_json::json!({"amount": 100})).unwrap(),
//! ).unwrap()
//! .build().unwrap();
//! assert_eq!(event.topic().as_str(), "invoice.created");
//! ```
//!
//! [`eventuary`]: https://crates.io/crates/eventuary
#![cfg_attr(docsrs, feature(doc_cfg))]

mod collector;
mod context;
mod error;
mod event;
mod event_key;
mod field_map;
pub mod io;
mod metadata;
mod namespace;
mod organization;
pub mod partition;
mod payload;
mod payload_codec;
mod serialization;
mod snapshot;
mod topic;

pub use collector::EventCollector;
pub use context::{Context, ContextError, ContextValue};
pub use error::{Error, Result};
pub use event::{Event, EventId};
pub use event_key::EventKey;
pub use field_map::FieldMap;
pub use metadata::Metadata;
pub use namespace::Namespace;
pub use organization::OrganizationId;
pub use partition::Partition;
pub use payload_codec::{
    EventCodec, JsonPayloadCodec, PayloadCodec, PayloadEventCodec, PayloadPassthroughCodec,
};

pub use io::filter::{NamespacePattern, TopicPattern};
pub use io::position::PartitionableSubscription;
pub use io::position::{StartFrom, StartableSubscription, StopAt};
pub use payload::{ContentType, Payload};
pub use serialization::{SerializedEvent, SerializedPayload};
pub use snapshot::{Snapshot, SnapshotEventId};
pub use topic::Topic;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn root_reexports_filter_patterns() {
        let topic = TopicPattern::exact(Topic::new("invoice.created").unwrap());
        let namespace = NamespacePattern::prefix(Namespace::new("/billing").unwrap());
        assert!(topic.matches_topic(&Topic::new("invoice.created").unwrap()));
        assert!(namespace.matches_namespace(&Namespace::new("/billing/invoices").unwrap()));
    }
}