1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//! Event-Driven Architecture support for Armature
//!
//! This crate provides in-process event publishing and handling.
//!
//! ## Features
//!
//! - **Event Bus** - Publish/subscribe event system
//! - **Event Handlers** - Decorator-based event handling
//! - **Type-safe** - Strong typing with compile-time safety
//! - **Async** - Full async/await support
//! - **Flexible** - Sync and async handler execution
//!
//! ## Quick Start
//!
//! ```rust,ignore
//! use armature_events::*;
//! use async_trait::async_trait;
//!
//! // Define an event
//! #[derive(Debug, Clone)]
//! struct UserCreatedEvent {
//! metadata: EventMetadata,
//! user_id: String,
//! email: String,
//! }
//!
//! impl Event for UserCreatedEvent {
//! fn event_name(&self) -> &str { "user_created" }
//! fn event_id(&self) -> Uuid { self.metadata.id }
//! fn timestamp(&self) -> DateTime<Utc> { self.metadata.timestamp }
//! fn as_any(&self) -> &dyn Any { self }
//! fn clone_event(&self) -> Box<dyn Event> { Box::new(self.clone()) }
//! }
//!
//! // Define a handler
//! #[derive(Clone)]
//! struct EmailHandler;
//!
//! #[async_trait]
//! impl EventHandler<UserCreatedEvent> for EmailHandler {
//! async fn handle(&self, event: &UserCreatedEvent) -> Result<(), EventHandlerError> {
//! println!("Sending welcome email to {}", event.email);
//! Ok(())
//! }
//! }
//!
//! // Use the event bus
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let bus = EventBus::new();
//!
//! // Subscribe handler
//! bus.subscribe::<UserCreatedEvent, _>(TypedEventHandler::new(EmailHandler));
//!
//! // Publish event
//! let event = UserCreatedEvent {
//! metadata: EventMetadata::new("user_created"),
//! user_id: "123".to_string(),
//! email: "alice@example.com".to_string(),
//! };
//!
//! bus.publish(event).await?;
//! Ok(())
//! }
//! ```
//!
//! ## Multiple Handlers
//!
//! ```rust,ignore
//! // Subscribe multiple handlers
//! bus.subscribe::<UserCreatedEvent, _>(TypedEventHandler::new(EmailHandler));
//! bus.subscribe::<UserCreatedEvent, _>(TypedEventHandler::new(AnalyticsHandler));
//! bus.subscribe::<UserCreatedEvent, _>(TypedEventHandler::new(AuditHandler));
//!
//! // All handlers will be invoked
//! bus.publish(event).await?;
//! ```
//!
//! ## Configuration
//!
//! ```rust,ignore
//! let bus = EventBusBuilder::new()
//! .async_handling(true) // Run handlers concurrently
//! .continue_on_error(true) // Don't stop on handler errors
//! .enable_logging(true) // Log events
//! .build();
//! ```
//!
//! ## Error Handling
//!
//! ```rust,ignore
//! let bus = EventBusBuilder::new()
//! .continue_on_error(false) // Stop on first error
//! .build();
//!
//! match bus.publish(event).await {
//! Ok(()) => println!("All handlers succeeded"),
//! Err(EventBusError::HandlersFailed(errors)) => {
//! eprintln!("Some handlers failed: {:?}", errors);
//! }
//! Err(e) => eprintln!("Publish error: {}", e),
//! }
//! ```
pub use ;
pub use ;