Trait Types

Source
pub trait Types
where Self: Debug + Default + PartialEq + Eq + Clone + 'static,
{ 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§

Source

type LogId: Debug + Clone + Ord + Eq + Codec + Send + Sync + 'static

Unique identifier for log entries. Usually it contains the term and log index.

Source

type LogPayload: Debug + Clone + Codec + Send + Sync + 'static

The actual data/command stored in log entries.

Source

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

Source

type Callback: Callback + Send + 'static

Callback handlers for notification of an IO operation.

Source

type UserData: Debug + Clone + Eq + Codec + 'static

Custom data that can be attached to Raft-log.

This data is not used by the Raft-log implementation, but it can be used by the user. For example, an application could attach a configuration or the node info in this field.

Required Methods§

Source

fn log_index(log_id: &Self::LogId) -> u64

Get the log index from the log id.

Source

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§

Source

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.

Implementors§