forked from databendlabs/openraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change: Add default value to
declare_raft_types
Types used in `declare_raft_types` can be omitted, in which case the default type will be used. The default values for each type are: - `D`: `String` - `R`: `String` - `NodeId`: `u64` - `Node`: `::openraft::BasicNode` - `Entry`: `::openraft::Entry<Self>` - `SnapshotData`: `Cursor<Vec<u8>>` - `AsyncRuntime`: `::openraft::TokioRuntime` Note that **The types must be specified in the exact order**: `D`, `R`, `NodeId`, `Node`, `Entry`, `SnapshotData`, `AsyncRuntime`. For example, to declare with only `D`, `R` and `Entry` types: ```rust,ignore openraft::declare_raft_types!( pub TypeConfig: D = ClientRequest, R = ClientResponse, Entry = MyEntry, ); ``` Type `NodeId`, `Node`, `SnapshotData` and `AsyncRuntime` will be filled with default values mentioned above. Or one can just use the default types for all: ```rust,ignore openraft::declare_raft_types!(pub TypeConfig); ``` Upgrade tip: Ensures types declared in `declare_raft_types` are in the correct order
- Loading branch information
1 parent
1d7a5ed
commit 8f0cc16
Showing
15 changed files
with
186 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! Test the `declare_raft_types` macro with default values | ||
|
||
use std::io::Cursor; | ||
|
||
use crate::declare_raft_types; | ||
use crate::TokioRuntime; | ||
|
||
declare_raft_types!( | ||
All: | ||
D = (), | ||
R = (), | ||
NodeId = u64, | ||
Node = (), | ||
Entry = crate::Entry<Self>, | ||
SnapshotData = Cursor<Vec<u8>>, | ||
AsyncRuntime = TokioRuntime, | ||
); | ||
|
||
declare_raft_types!( | ||
WithoutD: | ||
R = (), | ||
NodeId = u64, | ||
Node = (), | ||
Entry = crate::Entry<Self>, | ||
SnapshotData = Cursor<Vec<u8>>, | ||
AsyncRuntime = TokioRuntime, | ||
); | ||
|
||
declare_raft_types!( | ||
WithoutR: | ||
D = (), | ||
NodeId = u64, | ||
Node = (), | ||
Entry = crate::Entry<Self>, | ||
SnapshotData = Cursor<Vec<u8>>, | ||
AsyncRuntime = TokioRuntime, | ||
); | ||
|
||
// This raise an compile error: | ||
// > error: Type not in its expected position : NodeId = u64, D = (), types must present | ||
// > in this order : D, R, NodeId, Node, Entry, SnapshotData, AsyncRuntime | ||
// declare_raft_types!( | ||
// Foo: | ||
// Node = (), | ||
// NodeId = u64, | ||
// D = (), | ||
// ); | ||
|
||
declare_raft_types!(EmptyWithColon:); | ||
|
||
declare_raft_types!(Empty); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.