pub trait Types{
type LogId: Debug + Clone + Ord + Eq + Codec + Send + Sync + 'static;
type LogPayload: Debug + Clone + Codec + Send + Sync + 'static;
type Vote: Debug + Clone + PartialOrd + Eq + Codec + 'static;
type Callback: Callback + Send + 'static;
type UserData: Debug + Clone + Eq + Codec + 'static;
// Required methods
fn log_index(log_id: &Self::LogId) -> u64;
fn payload_size(payload: &Self::LogPayload) -> u64;
// Provided method
fn next_log_index(log_id: Option<&Self::LogId>) -> u64 { ... }
}Expand description
The Types trait defines the core type parameters used throughout the
Raft-log implementation.
This trait provides an abstraction layer for the log implementation by defining the core types used throughout the system. Implementations can customize the concrete types for: log id, log payload, vote, callback, and user data.
Required Associated Types§
Sourcetype LogId: Debug + Clone + Ord + Eq + Codec + Send + Sync + 'static
type LogId: Debug + Clone + Ord + Eq + Codec + Send + Sync + 'static
Unique identifier for log entries. Usually it contains the term and log index.
Sourcetype LogPayload: Debug + Clone + Codec + Send + Sync + 'static
type LogPayload: Debug + Clone + Codec + Send + Sync + 'static
The actual data/command stored in log entries.
Sourcetype Vote: Debug + Clone + PartialOrd + Eq + Codec + 'static
type Vote: Debug + Clone + PartialOrd + Eq + Codec + 'static
Representation of vote in leader election.
A vote typically contains:
- The election term number
- The candidate node ID
- A commitment flag indicating whether a quorum of nodes has granted this vote
The commitment flag is set to true when a majority of nodes in the cluster have voted for this candidate in this term.
In some raft implementation the vote is called hard state
Required Methods§
Sourcefn payload_size(payload: &Self::LogPayload) -> u64
fn payload_size(payload: &Self::LogPayload) -> u64
Get the payload size from the log payload.
The returned size does not have to be accurate. It is only used to estimate the space occupied in the cache.
Provided Methods§
Sourcefn next_log_index(log_id: Option<&Self::LogId>) -> u64
fn next_log_index(log_id: Option<&Self::LogId>) -> u64
Get the next log index from the log id.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.