use crate::{ log_array::LogArray, persister::PersistedRaftState, Index, Peer, Term, }; #[derive(Debug, Eq, PartialEq)] pub(crate) enum State { Follower, Candidate, // TODO: add PreVote Leader, } pub(crate) struct RaftState { pub current_term: Term, pub voted_for: Option, pub log: LogArray, pub commit_index: Index, pub last_applied: Index, pub next_index: Vec, pub match_index: Vec, pub current_step: Vec, pub state: State, pub leader_id: Peer, } impl RaftState { pub fn persisted_state(&self) -> PersistedRaftState { self.into() } } impl RaftState { pub fn is_leader(&self) -> bool { self.state == State::Leader } }