use core::fmt::Debug;
use serde::{Serialize, de::DeserializeOwned};
use crate::{BufferOverflowOr, Database, DatabaseError, Storage, Unifiable, UnifiableRef, Unifier};
pub trait RecordKey: Serialize + DeserializeOwned + Clone + Eq + UnifiableRef {
type Record: DatabaseEntry;
}
pub trait DeriveKey {
type Key: RecordKey;
fn key(c: &<Self::Key as RecordKey>::Record) -> Self::Key;
}
pub trait Index: Unifiable + Debug {
type Key: Unifiable + Clone + Eq + Debug;
type Record: DatabaseEntry;
const INDEX: u8;
}
pub trait Incrementable: Default + Sized {
fn next_id(&self) -> Option<Self>;
}
#[allow(unused_variables)] pub trait DatabaseEntry: Scope + Serialize + DeserializeOwned + Debug {
type Key: RecordKey;
const INDEX_COUNT_HINT: u8 = 0;
fn index_key<KU: Unifier>(
&self,
buffer: &mut KU::D,
discriminator: u8,
serializer: &KU,
) -> Result<(), BufferOverflowOr<KU::SerError>> {
Ok(())
}
}
pub trait Manifests<T: Scope + DatabaseEntry> {
fn last(&mut self) -> &mut Option<T::Key>;
}
pub trait Manifest: Default {
fn members() -> &'static [u8];
fn load<S: Storage>(&mut self, db: &mut Database<S, Self>) -> Result<(), DatabaseError<S>>
where
Self: Sized;
}
pub trait Scope {
const SCOPE: u8;
type Manifest;
}