#[non_exhaustive]pub enum Message {
PreVote(PreVote),
PreVoteReply(PreVoteReply),
RequestVote(RequestVote),
RequestVoteReply(RequestVoteReply),
AppendEntries(AppendEntries),
AppendEntriesReply(AppendEntriesReply),
InstallSnapshot(InstallSnapshot),
InstallSnapshotReply(InstallSnapshotReply),
TimeoutNow(TimeoutNow),
}Expand description
Any message a node can send or receive.
Wraps the RPCs and their replies. The enum is
#[non_exhaustive]:
future versions may add variants, so a match over a Message must include
a wildcard arm.
§Examples
use raft_io::{Message, RequestVote};
let msg = Message::RequestVote(RequestVote {
term: 1,
candidate: 1,
last_log_index: 0,
last_log_term: 0,
force: false,
});
match msg {
Message::RequestVote(rv) => assert_eq!(rv.term, 1),
_ => unreachable!(),
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
PreVote(PreVote)
A candidate is probing for support before a real election.
PreVoteReply(PreVoteReply)
A peer is answering a pre-vote probe.
RequestVote(RequestVote)
A candidate is asking for a vote.
RequestVoteReply(RequestVoteReply)
A peer is answering a vote request.
AppendEntries(AppendEntries)
A leader is replicating entries or sending a heartbeat.
AppendEntriesReply(AppendEntriesReply)
A follower is answering an append.
InstallSnapshot(InstallSnapshot)
A leader is shipping a snapshot to a far-behind follower.
InstallSnapshotReply(InstallSnapshotReply)
A follower is acknowledging an installed snapshot.
TimeoutNow(TimeoutNow)
A leader is handing off leadership, telling the target to campaign now.
Implementations§
Source§impl Message
impl Message
Sourcepub fn term(&self) -> Term
pub fn term(&self) -> Term
Returns the term carried by the message, whatever its variant.
The protocol checks the term of every inbound message first — a higher term forces the node to step down — so a single accessor avoids matching at each call site.
§Examples
use raft_io::{AppendEntriesReply, Message};
let m = Message::AppendEntriesReply(AppendEntriesReply {
term: 5,
success: false,
from: 2,
match_index: 0,
conflict_index: 1,
conflict_term: 0,
});
assert_eq!(m.term(), 5);