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
use crate::{pool_item::PoolItem, request_response::RequestResponse};
use super::ThreadRequestResponse;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ThreadEchoResponse {
thread_id: usize,
message: String,
responding_thread_id: usize,
}
impl ThreadEchoResponse {
pub fn new(thread_id: usize, message: String, responding_thread_id: usize) -> Self {
Self {
thread_id,
message,
responding_thread_id,
}
}
pub fn thread_id(&self) -> usize {
self.thread_id
}
pub fn message(&self) -> &str {
self.message.as_ref()
}
pub fn responding_thread_id(&self) -> usize {
self.responding_thread_id
}
}
impl<T> From<ThreadEchoResponse> for ThreadRequestResponse<T>
where
T: PoolItem,
{
fn from(request: ThreadEchoResponse) -> Self {
ThreadRequestResponse::ThreadEcho(RequestResponse::Response(request))
}
}
impl<P> From<ThreadRequestResponse<P>> for ThreadEchoResponse
where
P: PoolItem,
{
fn from(response: ThreadRequestResponse<P>) -> Self {
let ThreadRequestResponse::<P>::ThreadEcho(RequestResponse::Response(response)) = response else {
panic!("unexpected")
};
response
}
}