use std::fmt;
use std::fmt::Formatter;
use display_more::DisplayOptionExt;
use crate::RaftTypeConfig;
use crate::type_config::alias::LeaderIdOf;
use crate::type_config::alias::VoteOf;
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub struct LeaderChanged<C>
where C: RaftTypeConfig
{
pub expected_leader: LeaderIdOf<C>,
pub current_vote: Option<VoteOf<C>>,
}
impl<C> fmt::Display for LeaderChanged<C>
where C: RaftTypeConfig
{
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(
f,
"LeaderChanged: from {} to vote {}",
self.expected_leader,
self.current_vote.display()
)
}
}
impl<C> LeaderChanged<C>
where C: RaftTypeConfig
{
pub fn new(expected_leader: LeaderIdOf<C>, current_vote: Option<VoteOf<C>>) -> Self {
Self {
expected_leader,
current_vote,
}
}
}