use std::fmt::Debug;
use std::marker::PhantomData;
use chunked_wal::Callback;
use codeq::Codec;
use crate::RaftLogAction;
use crate::WalTypes;
use crate::raft_log::state_machine::raft_log_state::RaftLogState;
pub trait Types
where Self: Debug + Default + PartialEq + Eq + Clone + 'static
{
type LogId: Debug + Clone + Ord + Eq + Codec + Send + Sync + 'static;
type LogPayload: Debug + Clone + Codec + Send + Sync + 'static;
type Vote: Debug + Clone + PartialOrd + Eq + Codec + Send + Sync + 'static;
type Callback: Callback;
type UserData: Debug + Clone + Eq + Codec + Send + Sync + 'static;
fn log_index(log_id: &Self::LogId) -> u64;
fn payload_size(payload: &Self::LogPayload) -> u64;
fn next_log_index(log_id: Option<&Self::LogId>) -> u64 {
match log_id {
Some(log_id) => Self::log_index(log_id) + 1,
None => 0,
}
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct RaftWalTypes<T>(PhantomData<T>);
impl<T> WalTypes for RaftWalTypes<T>
where T: Types
{
type Action = RaftLogAction<T>;
type Checkpoint = RaftLogState<T>;
type Callback = T::Callback;
}