use std::io::Cursor;
use openraft_rt_tokio::TokioRuntime;
use crate::Node;
use crate::OptionalSend;
use crate::RaftTypeConfig;
use crate::type_config::alias::DefaultEntryOf;
use crate::type_config::alias::LeaderIdOf;
use crate::type_config::alias::LogIdOf;
use crate::type_config::alias::NodeIdOf;
use crate::vote::RaftLeaderIdExt;
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub(crate) struct UTConfig<N = ()> {
_p: std::marker::PhantomData<N>,
}
impl<N> Default for UTConfig<N> {
fn default() -> Self {
Self {
_p: std::marker::PhantomData,
}
}
}
impl<N> Clone for UTConfig<N> {
fn clone(&self) -> Self {
*self
}
}
impl<N> Copy for UTConfig<N> {}
impl<N> RaftTypeConfig for UTConfig<N>
where N: Node + Ord
{
type D = u64;
type R = ();
type NodeId = u64;
type Node = N;
type Term = u64;
type LeaderId = crate::impls::leader_id_adv::LeaderId<u64, u64>;
type Vote = crate::impls::Vote<Self::LeaderId>;
type Entry = DefaultEntryOf<Self>;
type SnapshotData = Cursor<Vec<u8>>;
type AsyncRuntime = TokioRuntime;
type Responder<T>
= crate::impls::OneshotResponder<Self, T>
where T: OptionalSend + 'static;
type Batch<T>
= crate::impls::InlineBatch<T>
where T: OptionalSend + 'static;
type ErrorSource = anyerror::AnyError;
}
pub(crate) type UTLeaderId = crate::impls::leader_id_adv::LeaderId<u64, u64>;
pub(crate) type UtClid = UTLeaderId;
pub(crate) fn log_id(term: u64, node_id: NodeIdOf<UTConfig>, index: u64) -> LogIdOf<UTConfig> {
LogIdOf::<UTConfig>::new(LeaderIdOf::<UTConfig>::new_committed(term, node_id), index)
}