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
use super::{Message, RequestId};
use crate::Metadata;
/// Business request to send, including an identifier, body, and metadata.
#[derive(Clone, Debug)]
pub struct Request {
/// Identifier used to correlate the business response.
id: RequestId,
/// Text or binary body sent on the wire.
message: Message,
/// Additional metadata; size validation occurs during send admission.
metadata: Metadata,
}
impl Request {
/// Creates a request with empty metadata.
pub fn new(id: RequestId, message: Message) -> Self {
Self {
id,
message,
metadata: Metadata::new(),
}
}
/// Replaces the request metadata.
pub fn with_metadata(mut self, metadata: Metadata) -> Self {
self.metadata = metadata;
self
}
/// Borrows the request identifier.
pub fn id(&self) -> &RequestId {
&self.id
}
/// Borrows the request body.
pub fn message(&self) -> &Message {
&self.message
}
/// Borrows request metadata.
pub fn metadata(&self) -> &Metadata {
&self.metadata
}
/// Consumes the request and returns its components.
pub fn into_parts(self) -> (RequestId, Message, Metadata) {
(self.id, self.message, self.metadata)
}
}