use crate::storage::Table;
use gnitz_zset::repr::StorageError;
use gnitz_zset::schema::SchemaDescriptor;
pub(crate) enum Store {
Held(Box<Table>),
Absent(Box<SchemaDescriptor>),
}
impl Store {
pub(crate) fn schema(&self) -> &SchemaDescriptor {
match self {
Store::Held(t) => t.schema(),
Store::Absent(s) => s,
}
}
pub(crate) fn swap_schema(&mut self, schema: SchemaDescriptor) -> Result<(), StorageError> {
match self {
Store::Held(t) => t.swap_schema(schema),
Store::Absent(s) => {
**s = schema;
Ok(())
}
}
}
#[track_caller]
pub(crate) fn held(&self) -> &Table {
match self {
Store::Held(t) => t,
Store::Absent(_) => not_held(),
}
}
#[track_caller]
pub(crate) fn held_mut(&mut self) -> &mut Table {
match self {
Store::Held(t) => t,
Store::Absent(_) => not_held(),
}
}
pub(in crate::relation) fn table_mut(&mut self) -> Option<&mut Table> {
match self {
Store::Held(t) => Some(t),
Store::Absent(_) => None,
}
}
}
#[cold]
#[track_caller]
fn not_held() -> ! {
panic!("relation store is not held by this process")
}