Macro openraft::declare_raft_types

source ยท
macro_rules! declare_raft_types {
    ($(#[$outer:meta])* $visibility:vis $id:ident) => { ... };
    ($(#[$outer:meta])* $visibility:vis $id:ident: $($(#[$inner:meta])* $type_id:ident = $type:ty),* $(,)? ) => { ... };
}
Expand description

Define types for a Raft type configuration.

Since Rust has some limitations when deriving traits for types with generic arguments and most types are parameterized by RaftTypeConfig, we need to add supertraits to a type implementing RaftTypeConfig.

This macro does exactly that.

Example:

โ“˜
openraft::declare_raft_types!(
   pub TypeConfig:
       D            = ClientRequest,
       R            = ClientResponse,
       NodeId       = u64,
       Node         = openraft::BasicNode,
       Entry        = openraft::Entry<TypeConfig>,
       SnapshotData = Cursor<Vec<u8>>,
       Responder    = openraft::impls::OneshotResponder<TypeConfig>,
       AsyncRuntime = openraft::TokioRuntime,
);

Types can be omitted, and the following default type will be used:

  • D: String
  • R: String
  • NodeId: u64
  • Node: ::openraft::impls::BasicNode
  • Entry: ::openraft::impls::Entry<Self>
  • SnapshotData: Cursor<Vec<u8>>
  • Responder: ::openraft::impls::OneshotResponder<Self>
  • AsyncRuntime: ::openraft::impls::TokioRuntime

For example, to declare with only D and R types:

โ“˜
openraft::declare_raft_types!(
   pub TypeConfig:
       D = ClientRequest,
       R = ClientResponse,
);

Or just use the default type config:

โ“˜
openraft::declare_raft_types!(pub TypeConfig);