10
10
//
11
11
// SPDX-License-Identifier: Apache-2.0 OR MIT
12
12
13
+ //! # Example
14
+ //!
15
+ //! ## Typed API
16
+ //!
17
+ //! ```
18
+ //! use iceoryx2::prelude::*;
19
+ //! # fn main() -> Result<(), Box<dyn core::error::Error>> {
20
+ //! # let node = NodeBuilder::new().create::<ipc::Service>()?;
21
+ //! #
22
+ //! # let service = node.service_builder(&"My/Funk/ServiceName".try_into()?)
23
+ //! # .request_response::<u64, u64>()
24
+ //! # .open_or_create()?;
25
+ //! #
26
+ //! let client = service.client_builder().create()?;
27
+ //! # let server = service.server_builder().create()?;
28
+ //! let pending_response = client.send_copy(0)?;
29
+ //! # let active_request = server.receive()?.unwrap();
30
+ //! # active_request.send_copy(0)?;
31
+ //!
32
+ //! if let Some(response) = pending_response.receive()? {
33
+ //! println!("received response: {} from: {}",
34
+ //! response.payload(), response.header().server_id());
35
+ //! }
36
+ //!
37
+ //! # Ok(())
38
+ //! # }
39
+ //! ```
40
+
13
41
use core:: fmt:: Debug ;
14
42
use core:: ops:: Deref ;
15
43
@@ -22,6 +50,10 @@ use crate::port::port_identifiers::UniqueServerId;
22
50
use crate :: raw_sample:: RawSample ;
23
51
use crate :: service;
24
52
53
+ /// It stores the payload and can be received by the
54
+ /// [`PendingResponse`](crate::pending_response::PendingResponse) after a
55
+ /// [`RequestMut`](crate::request_mut::RequestMut) was sent to a
56
+ /// [`Server`](crate::port::server::Server) via the [`Client`](crate::port::client::Client).
25
57
pub struct Response < Service : crate :: service:: Service , ResponsePayload : Debug , ResponseHeader : Debug >
26
58
{
27
59
pub ( crate ) ptr : RawSample <
@@ -85,18 +117,24 @@ impl<Service: crate::service::Service, ResponsePayload: Debug, ResponseHeader: D
85
117
impl < Service : crate :: service:: Service , ResponsePayload : Debug , ResponseHeader : Debug >
86
118
Response < Service , ResponsePayload , ResponseHeader >
87
119
{
120
+ /// Returns a reference to the
121
+ /// [`ResponseHeader`](service::header::request_response::ResponseHeader).
88
122
pub fn header ( & self ) -> & service:: header:: request_response:: ResponseHeader {
89
123
self . ptr . as_header_ref ( )
90
124
}
91
125
126
+ /// Returns a reference to the user header of the response.
92
127
pub fn user_header ( & self ) -> & ResponseHeader {
93
128
self . ptr . as_user_header_ref ( )
94
129
}
95
130
131
+ /// Returns a reference to the payload of the response.
96
132
pub fn payload ( & self ) -> & ResponsePayload {
97
133
self . ptr . as_payload_ref ( )
98
134
}
99
135
136
+ /// Returns the [`UniqueServerId`] of the [`Server`](crate::port::server::Server) which sent
137
+ /// the [`Response`].
100
138
pub fn origin ( & self ) -> UniqueServerId {
101
139
UniqueServerId ( UniqueSystemId :: from ( self . details . origin ) )
102
140
}
0 commit comments