use crate::db::schema::FieldId;
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub(in crate::db) struct SchemaVersion(u32);
impl SchemaVersion {
#[must_use]
pub(in crate::db) const fn initial() -> Self {
Self(1)
}
#[must_use]
pub(in crate::db) const fn get(self) -> u32 {
self.0
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub(in crate::db) struct SchemaFieldSlot(u16);
impl SchemaFieldSlot {
#[must_use]
pub(in crate::db) fn from_generated_index(index: usize) -> Self {
let slot = u16::try_from(index).expect("generated field slot should fit in persisted u16");
Self(slot)
}
#[must_use]
pub(in crate::db) const fn get(self) -> u16 {
self.0
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(in crate::db) struct SchemaRowLayout {
version: SchemaVersion,
field_to_slot: Vec<(FieldId, SchemaFieldSlot)>,
}
impl SchemaRowLayout {
#[must_use]
pub(in crate::db) const fn new(
version: SchemaVersion,
field_to_slot: Vec<(FieldId, SchemaFieldSlot)>,
) -> Self {
Self {
version,
field_to_slot,
}
}
#[must_use]
pub(in crate::db) const fn version(&self) -> SchemaVersion {
self.version
}
#[must_use]
pub(in crate::db) const fn field_to_slot(&self) -> &[(FieldId, SchemaFieldSlot)] {
self.field_to_slot.as_slice()
}
}