use std::future::Future;
use futures_core::Stream;
use crate::{
GetError, ResponseHeader, Revision,
client::{
Compact, CompactError, CompactResponse, CountResponse, Delete, DeleteError, DeleteResponse, Get, GetResponse,
List, Put, PutError, PutResponse, Transaction, TransactionError, TransactionResponse,
},
record::{KeyWithMetadata, Record},
};
pub trait KvDriver {
type GetFuture: Future<Output = Result<GetResponse, GetError>> + Send;
type PutFuture<R>: Future<Output = Result<PutResponse<R>, PutError>> + Send;
type DeleteFuture<R, P>: Future<Output = Result<DeleteResponse<R, P>, DeleteError>> + Send;
type ListView<R>: ListView<R>;
type ListViewFuture<R>: Future<Output = Result<Self::ListView<R>, GetError>> + Send;
type CountFuture: Future<Output = Result<CountResponse, GetError>> + Send;
type CommitFuture: Future<Output = Result<TransactionResponse, TransactionError>> + Send;
type CompactFuture: Future<Output = Result<CompactResponse, CompactError>> + Send;
fn execute_get(self, get: Get<()>) -> Self::GetFuture;
fn execute_put<R>(self, put: Put<(), R>) -> Self::PutFuture<R>;
fn execute_delete<R, P>(self, delete: Delete<(), R, P>) -> Self::DeleteFuture<R, P>;
fn execute_list_records(self, list: List<(), Record>) -> Self::ListViewFuture<Record>;
fn execute_list_keys(self, list: List<(), KeyWithMetadata>) -> Self::ListViewFuture<KeyWithMetadata>;
fn execute_count(self, list: List<(), usize>) -> Self::CountFuture;
fn execute_transaction(self, txn: Transaction<()>) -> Self::CommitFuture;
fn execute_compact(self, compact: Compact<()>) -> Self::CompactFuture;
}
pub trait ListView<R> {
type Stream: Stream<Item = Result<R, GetError>> + Send;
fn header(&self) -> &ResponseHeader;
fn revision(&self) -> Revision {
self.header().revision()
}
fn into_stream(self) -> Self::Stream;
}