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 crateRaftTypeConfig;
use crateApplyResponderInner;
/// Responder for sending client write responses after applying an entry.
///
/// This wrapper enables zero-allocation response handling by allowing state machines
/// to send responses immediately after applying each entry, rather than buffering
/// them in a Vec.
///
/// # Construction
///
/// This type cannot be constructed by user code. Instances are provided by
/// Openraft when entries are passed to [`RaftStateMachine::apply`](super::RaftStateMachine::apply).
/// State machine implementations should call [`send()`](Self::send) to
/// return the response after applying each entry.
///
/// # Example
///
/// ```ignore
/// use openraft::storage::EntryResponder;
/// use openraft::StorageError;
/// use openraft::EntryPayload;
///
/// async fn apply<I>(&mut self, entries: I) -> Result<(), StorageError<C>>
/// where
/// I: IntoIterator<Item = EntryResponder<C>>,
/// I::IntoIter: Send,
/// {
/// for (entry, responder) in entries {
/// // Compute response based on entry type
/// let response = match entry.payload {
/// EntryPayload::Blank => Response::default(),
/// EntryPayload::Normal(ref data) => {
/// self.apply_normal_entry(data)?;
/// self.compute_response(data)?
/// }
/// EntryPayload::Membership(ref mem) => {
/// self.apply_membership_change(mem)?;
/// Response::default()
/// }
/// };
///
/// // Send response only when there's a client waiting (leader entries)
/// if let Some(responder) = responder {
/// responder.send(response);
/// }
/// }
/// Ok(())
/// }
/// ```