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
use pool_item;
// Allow the macro to refer to the crate by name
use crate as messaging_thread_pool;
/// A simple chat room that manages a history of messages.
///
/// This sample demonstrates the most basic `#[pool_item]` usage with:
/// - Mutable state (the `history` vector)
/// - Multiple message types (`post`, `get_history`)
/// - Minimal boilerplate
///
/// # Generated Types
///
/// The `#[pool_item]` macro generates:
/// - `ChatRoomInit(u64)` - Create a new chat room with the given ID
/// - `ChatRoomApi` - Enum of message types
/// - `PostRequest(u64, String, String)` - Post a message (id, user, text)
/// - `PostResponse { id, result }` - Response with message index
/// - `GetHistoryRequest(u64)` - Request message history
/// - `GetHistoryResponse { id, result }` - Response with history vector
///
/// # Example
///
/// ```rust
/// use messaging_thread_pool::{ThreadPool, samples::*};
///
/// let pool = ThreadPool::<ChatRoom>::new(2);
///
/// // Create room with ID 1
/// pool.send_and_receive_once(ChatRoomInit(1)).unwrap();
///
/// // Post messages
/// pool.send_and_receive_once(PostRequest(1, "Alice".into(), "Hello!".into())).unwrap();
/// pool.send_and_receive_once(PostRequest(1, "Bob".into(), "Hi Alice!".into())).unwrap();
///
/// // Get history
/// let history = pool.send_and_receive_once(GetHistoryRequest(1)).unwrap();
/// assert_eq!(history.result.len(), 2);
/// assert_eq!(history.result[0], "Alice: Hello!");
/// ```
///
/// # Note
///
/// This is the simplest example in the samples. For shared state patterns with
/// `Rc<RefCell<T>>`, see [`UserSession`](super::UserSession).