cuprate/database/src/table.rs
hinto-janai 3656a1ada7
database: return owned T in Storable (#92)
* add `storable_slice.rs`

* storable: `from_bytes(&[u8]) -> Self`

* heed: return `T` in `Storable`, use `StorableSlice` in tests

* remove `value_guard.rs`

* redb: update `Storable` to return owned `T`

* database: return `T` directly, remove `'a` lifetime

* replace `[]` with `StorableSlice`

* tables: add lifetime to `tables!()` and generated structs

* backend: fix tests

* heed: update fn signatures

* storable: add `StorableVec`, remove `Storable::ALIGN`

* tables/types: remove slice lifetimes, use `StorableVec`

* backend: use `StorableVec`, fix tests

* types: fix tests to use owned returned value

* heed: fix `Storable` impl and tests

* storable: `StorableVec` docs + tests

* backend: assert values are detached from `get_range()` iterator

* database: add docs

* udpate docs, remove unneeded clippy `allow`

* replace `ToOwnedDebug` with `std::fmt::Debug`

* impl `StorableBytes`

* backend: add `StorableBytes` to tests

* readme: remove `to_owned_debug.rs` reference
2024-03-22 21:11:48 +00:00

32 lines
1.1 KiB
Rust

//! Database table abstraction; `trait Table`.
//---------------------------------------------------------------------------------------------------- Import
use std::fmt::Debug;
use crate::{key::Key, storable::Storable};
//---------------------------------------------------------------------------------------------------- Table
/// Database table metadata.
///
/// Purely compile time information for database tables.
///
/// ## Sealed
/// This trait is [`Sealed`](https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed).
///
/// It is, and can only be implemented on the types inside [`tables`][crate::tables].
pub trait Table: crate::tables::private::Sealed + 'static {
/// Name of the database table.
const NAME: &'static str;
/// Primary key type.
type Key: Key + 'static;
/// Value type.
type Value: Storable + 'static;
}
//---------------------------------------------------------------------------------------------------- Tests
#[cfg(test)]
mod test {
// use super::*;
}