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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//
// ░▀█▀░█▀▀░█▀█░█▀▄░█▀█░█▀▀░█░░░█▀▀
// ░░█░░▀▀█░█░█░█▀▄░█▀█░█░░░█░░░█▀▀
// ░░▀░░▀▀▀░▀▀▀░▀░▀░▀░▀░▀▀▀░▀▀▀░▀▀▀
//
// tsoracle — Distributed Timestamp Oracle
//
// Copyright (c) 2026 Prisma Risk
// Licensed under the Apache License, Version 2.0
// https://github.com/prisma-risk/tsoracle
//
//! Macros for declaring an openraft `RaftTypeConfig` with sensible defaults.
//!
//! Consumers supply only the slots that actually vary (`Node`, `AppData`,
//! `AppDataResponse`, `SnapshotData`, optionally `NodeId`/`Entry`/`AsyncRuntime`/
//! `Responder`); everything else is inherited from the defaults below.
//!
//! # Why a direct trait impl instead of wrapping `openraft::declare_raft_types!`
//!
//! openraft 0.10.0-alpha.20's `declare_raft_types!` macro does not accept a
//! `Responder<T> = ...` override — its `Responder<T>` slot has a `where` clause
//! that the macro's `$type_id:ident = $type:ty` entry grammar can't express.
//! The openraft test file (`raft/declare_raft_types_test.rs`) calls this out
//! explicitly:
//!
//! ```text
//! // Responder<T> is not supported by declare_raft_types
//! ```
//!
//! The openraft macro's hard-coded default is `ProgressResponder<Self, T>`.
//! Defaulting to `OneshotResponder<Self, T>` instead therefore requires
//! emitting an `impl RaftTypeConfig` block directly. That also gives the macro
//! full control over `LeaderId`, `Vote`, `Entry`, `Batch`, and `ErrorSource`,
//! so the produced impl is identical to a hand-written one.
/// Declare a `RaftTypeConfig` with sensible defaults.
///
/// Required slots:
/// - `Node` — peer metadata (must satisfy openraft's `Node` bounds:
/// `Clone + Default + Eq + PartialEq + Debug + Serialize + DeserializeOwned + Send + Sync + 'static`)
/// - `AppData` — log entry payload (openraft's `D`)
/// - `AppDataResponse` — state-machine apply result (openraft's `R`)
/// - `SnapshotData` — snapshot wire format (must satisfy openraft's
/// `AsyncRead + AsyncSeek + AsyncWrite + Unpin + Send + 'static`)
///
/// Optional overrides:
/// - `NodeId` (default `u64`)
/// - `Entry` (default
/// `openraft::Entry<<Self::LeaderId as openraft::vote::RaftLeaderId>::Committed, Self::D, Self::NodeId, Self::Node>`)
/// - `AsyncRuntime` (default `openraft::impls::TokioRuntime`)
/// - `Responder` — accepts a **fully instantiated** `Responder<C, T>` type
/// where `C` and `T` are the GAT's in-scope `Self` and `T` (i.e. write the
/// override as `openraft::impls::OneshotResponder<Self, T>`). Default
/// `openraft::impls::OneshotResponder<Self, T>`.
///
/// Inherited (non-overridable) defaults:
/// - `Term = u64`
/// - `LeaderId = openraft::impls::leader_id_adv::LeaderId<Self::Term, Self::NodeId>`
/// (multi-leader-per-term)
/// - `Vote = openraft::impls::Vote<Self::LeaderId>`
/// - `Batch<T> = openraft::impls::InlineBatch<T>`
/// - `ErrorSource = openraft::impls::BoxedErrorSource`
///
/// # Examples
///
/// ```ignore
/// use tsoracle_openraft_toolkit::declare_raft_types_ext;
///
/// declare_raft_types_ext! {
/// pub MyTypeConfig:
/// Node = MyPeer,
/// AppData = MyLogEntry,
/// AppDataResponse = MyAppliedState,
/// SnapshotData = std::io::Cursor<Vec<u8>>,
/// }
/// ```