pub use nimiq_database_value::{AsDatabaseBytes, FromDatabaseBytes};
pub trait Key: AsDatabaseBytes + FromDatabaseBytes + Ord + 'static {}
impl<T: AsDatabaseBytes + FromDatabaseBytes + Ord + 'static> Key for T {}
pub trait Value: AsDatabaseBytes + FromDatabaseBytes + 'static {}
impl<T: AsDatabaseBytes + FromDatabaseBytes + 'static> Value for T {}
pub trait DupTableValue: Value {
type SubKey: Key;
type Value: Value;
fn subkey(&self) -> &Self::SubKey;
fn value(&self) -> &Self::Value;
}
pub trait Table {
const NAME: &'static str;
type Key: Key;
type Value: Value;
}
pub trait RegularTable: Table {}
pub trait DupTable: Table {}
#[macro_export]
macro_rules! declare_table {
($typ:ident, $name:expr, $key:ty, $value:ty) => {
#[derive(Clone, Debug, Default)]
pub struct $typ;
impl $crate::traits::Table for $typ {
const NAME: &'static str = $name;
type Key = $key;
type Value = $value;
}
};
($typ:ident, $name:expr, $key:ty => dup($value:ty)) => {
$crate::declare_table!($typ, $name, $key, $value);
impl $crate::traits::DupTable for $typ {}
};
($typ:ident, $name:expr, $key:ty => $value:ty) => {
$crate::declare_table!($typ, $name, $key, $value);
impl $crate::traits::RegularTable for $typ {}
};
($typ:ident, $name:expr, $key:ty => $subkey:ty => $value:ty) => {
$crate::declare_table!($typ, $name, $key, $crate::utils::IndexedValue<$subkey, $value>);
impl $crate::traits::DupTable for $typ {}
};
}