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
use Debug;
/// A trait for types that have an ID used for routing within the thread pool.
///
/// This trait is fundamental to how `messaging_thread_pool` works. The ID is used to:
/// - Route requests to the correct thread (`id % thread_count`)
/// - Identify which pool item should process a message
/// - Associate responses with their original requests
///
/// # Implementation Requirements
///
/// - IDs must be unique within a thread pool for pool items
/// - IDs should be stable (not change during the object's lifetime)
/// - The `id()` method should be cheap to call (typically just returning a field)
///
/// # Example
///
/// ```rust
/// use messaging_thread_pool::IdTargeted;
///
/// #[derive(Debug)]
/// struct MyItem {
/// id: u64,
/// data: String,
/// }
///
/// impl IdTargeted for MyItem {
/// fn id(&self) -> u64 {
/// self.id
/// }
/// }
///
/// // Request types also implement IdTargeted
/// #[derive(Debug)]
/// struct MyRequest(u64, String);
///
/// impl IdTargeted for MyRequest {
/// fn id(&self) -> u64 {
/// self.0 // First field is the target ID
/// }
/// }
/// ```
///
/// # Note on Generated Types
///
/// When using the `#[pool_item]` macro, `IdTargeted` is automatically implemented
/// for all generated request and response types. You only need to implement it
/// manually for:
/// - Your pool item struct
/// - Custom initialization request types (when using `Init = "..."`)