#[cfg(not(feature = "storage-v2"))] use std::future::Future;
use openraft_macros::add_async_trait;
#[cfg(not(feature = "storage-v2"))] use crate::storage::Adaptor;
use crate::storage::RaftLogStorage;
use crate::storage::RaftStateMachine;
#[cfg(not(feature = "storage-v2"))] use crate::RaftStorage;
use crate::RaftTypeConfig;
use crate::StorageError;
#[add_async_trait]
pub trait StoreBuilder<C, LS, SM, G = ()>: Send + Sync
where
C: RaftTypeConfig,
LS: RaftLogStorage<C>,
SM: RaftStateMachine<C>,
{
async fn build(&self) -> Result<(G, LS, SM), StorageError<C::NodeId>>;
}
#[cfg(not(feature = "storage-v2"))]
impl<C, S, F, Fu> StoreBuilder<C, Adaptor<C, S>, Adaptor<C, S>, ()> for F
where
F: Send + Sync,
C: RaftTypeConfig,
S: RaftStorage<C>,
Fu: Future<Output = S> + Send,
F: Fn() -> Fu,
{
async fn build(&self) -> Result<((), Adaptor<C, S>, Adaptor<C, S>), StorageError<C::NodeId>> {
let store = self().await;
let (log_store, sm) = Adaptor::new(store);
Ok(((), log_store, sm))
}
}