use crate::Error;
use std::{future::Future, pin::Pin};
pub const PREFIX_LEN: usize = 4;
pub type Prefix = [u8; PREFIX_LEN];
pub type KvPairs = Vec<(Vec<u8>, Vec<u8>)>;
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
pub fn storage_key(prefix: &Prefix, suffix: &[u8]) -> Vec<u8> {
let mut key = Vec::with_capacity(PREFIX_LEN + suffix.len());
key.extend_from_slice(prefix);
key.extend_from_slice(suffix);
key
}
pub trait Storage: Send + Sync {
fn get(&self, key: &[u8]) -> BoxFuture<'_, Result<Option<Vec<u8>>, Error>>;
fn set(&self, key: &[u8], value: Vec<u8>) -> BoxFuture<'_, Result<(), Error>>;
fn increment(&self, key: &[u8], delta: i64) -> BoxFuture<'_, Result<i64, Error>>;
fn list(&self, prefix: &Prefix) -> BoxFuture<'_, Result<KvPairs, Error>>;
fn delete(&self, key: &[u8]) -> BoxFuture<'_, Result<(), Error>>;
}