use crate::log_id::raft_log_id::RaftLogId;
use crate::log_id::raft_log_id_ext::RaftLogIdExt;
use crate::log_id::ref_log_id::RefLogId;
pub(crate) trait OptionRaftLogIdExt<T>
where T: RaftLogId
{
fn index(&self) -> Option<u64>;
fn next_index(&self) -> u64;
#[allow(dead_code)]
fn committed_leader_id(&self) -> Option<&T::CommittedLeaderId>;
fn to_ref(&self) -> Option<RefLogId<'_, T::CommittedLeaderId>>;
}
impl<T> OptionRaftLogIdExt<T> for Option<T>
where T: RaftLogId
{
fn index(&self) -> Option<u64> {
self.as_ref().map(|x| x.index())
}
fn next_index(&self) -> u64 {
match self {
None => 0,
Some(log_id) => log_id.index() + 1,
}
}
fn committed_leader_id(&self) -> Option<&T::CommittedLeaderId> {
self.as_ref().map(|x| x.committed_leader_id())
}
fn to_ref(&self) -> Option<RefLogId<'_, T::CommittedLeaderId>> {
self.as_ref().map(|x| x.to_ref())
}
}