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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/// Advanced channel communication utilities for high-performance async messaging.
///
/// This module provides comprehensive channel-based communication primitives designed
/// for high-throughput, low-latency message passing between async tasks and threads.
/// Built on crossfire MPMC channels and smol async runtime for optimal performance.
///
/// ## Features
///
/// - **Multiple Channel Types**: Bounded, unbounded, and specialized channels
/// - **Message Monitoring**: Performance tracking and statistics collection
/// - **Multiplexing**: Route messages to multiple consumers efficiently
/// - **Queue Management**: Priority queues and specialized message handling
/// - **Specialized Channels**: Domain-specific channel implementations
/// - **Message Parsing**: Protocol-aware message processing and validation
/// - **Async Integration**: Seamless integration with smol async runtime
///
/// ## Architecture
///
/// ### Core Components
/// - **`core`**: Fundamental channel primitives and basic operations
/// - **`monitoring`**: Performance monitoring and statistics collection
/// - **`multiplexor`**: Message routing and fan-out capabilities
/// - **`queue`**: Advanced queue implementations with priorities
/// - **`specialist`**: Domain-specific channel specializations
/// - **`parsers`**: Message parsing and protocol handling
///
/// ## Examples
///
/// ### Basic Channel Communication
/// ```rust
/// use trash_utilities::channels::{bounded_queue_3, send_async, recv_async};
/// use smol;
///
/// # smol::block_on(async {
/// // Create a bounded channel
/// let (tx, rx) = bounded_queue_3::<String>(10);
///
/// // Send a message asynchronously
/// send_async(&tx, "Hello, channels!".to_string()).await.unwrap();
///
/// // Receive the message
/// let message = recv_async(&rx).await.unwrap();
/// assert_eq!(message, "Hello, channels!");
/// # });
/// ```
///
/// ### Message Monitoring
/// ```rust,no_run
/// use trash_utilities::channels::{create_monitored_channel, ChannelMonitor};
/// use smol;
///
/// # smol::block_on(async {
/// // Create a monitored channel
/// let (tx, rx, monitor) = create_monitored_channel::<String>(10);
///
/// // Send some messages
/// for i in 0..5 {
/// send_async(&tx, format!("Message {}", i)).await.unwrap();
/// }
///
/// // Check monitoring statistics
/// let stats = monitor.get_stats();
/// println!("Messages sent: {}", stats.messages_sent);
/// println!("Channel utilization: {:.1}%", stats.utilization_percent());
/// # });
/// ```
///
/// ### Message Multiplexing
/// ```rust,no_run
/// use trash_utilities::channels::{create_multiplexer, Multiplexer};
/// use smol;
///
/// # smol::block_on(async {
/// // Create a multiplexer for broadcasting messages
/// let mut multiplexer = create_multiplexer::<String>();
///
/// // Add multiple receivers
/// let rx1 = multiplexer.add_receiver();
/// let rx2 = multiplexer.add_receiver();
/// let tx = multiplexer.get_sender();
///
/// // Send a message (received by both consumers)
/// send_async(&tx, "Broadcast message".to_string()).await.unwrap();
///
/// // Both receivers get the message
/// let msg1 = recv_async(&rx1).await.unwrap();
/// let msg2 = recv_async(&rx2).await.unwrap();
/// assert_eq!(msg1, msg2);
/// # });
/// ```
///
/// ### Priority Queue
/// ```rust,no_run
/// use trash_utilities::channels::{create_priority_queue, PriorityMessage};
/// use smol;
///
/// # smol::block_on(async {
/// // Create a priority queue
/// let (tx, rx) = create_priority_queue::<String>(10);
///
/// // Send messages with different priorities
/// tx.send(PriorityMessage::high("Urgent!".to_string())).await.unwrap();
/// tx.send(PriorityMessage::low("Normal message".to_string())).await.unwrap();
/// tx.send(PriorityMessage::medium("Medium priority".to_string())).await.unwrap();
///
/// // High priority message received first
/// let urgent = rx.recv().await.unwrap();
/// assert_eq!(urgent.data, "Urgent!");
/// # });
/// ```
///
/// ### Protocol-Aware Parsing
/// ```rust,no_run
/// use trash_utilities::channels::{create_protocol_parser, ProtocolParser};
/// use smol;
///
/// # smol::block_on(async {
/// // Create a parser for a custom protocol
/// let (tx, rx) = create_protocol_parser::<String, ParsedMessage>(10);
///
/// // Send raw protocol messages
/// send_async(&tx, "CMD:LOGIN user=alice".to_string()).await.unwrap();
/// send_async(&tx, "DATA:Hello World".to_string()).await.unwrap();
///
/// // Receive parsed messages
/// let login_msg = recv_async(&rx).await.unwrap();
/// let data_msg = recv_async(&rx).await.unwrap();
///
/// match login_msg {
/// ParsedMessage::Command(cmd) => println!("Command: {}", cmd),
/// _ => {}
/// }
/// # });
/// ```
// Re-export core types and functions
pub use *;
// Re-export monitoring types
pub use *;
// Re-export multiplexer types
pub use *;
// Re-export queue types
pub use *;
// Re-export specialist types
pub use *;
// Re-export parsers types
pub use *;