Skip to main content

Versioned

Trait Versioned 

pub trait Versioned:
    Sized
    + Clone
    + Send
    + Sync
    + 'static {
    type Key: Ord + Clone + Hash + Send + Sync + 'static;

    const TABLE_NAME: &'static str;

    // Required methods
    fn table_id_cell() -> &'static OnceLock<TableId>;
    fn key(&self) -> Self::Key;
    fn key_bytes(&self) -> IndexKey;
    fn indexes() -> &'static [IndexDesc<Self>];

    // Provided method
    fn table_id() -> TableId { ... }
}
Expand description

A struct that the engine can store and version.

The bounds are the whole requirement: Clone because an update copies the record before mutating it into a new version, Send + Sync + 'static because versions outlive the transaction that wrote them. Fields are otherwise unconstrained — there is no serialisation trait to satisfy.

Users never implement this by hand — #[derive(Mvcc)] generates it from field attributes. It is public because it appears in the bounds of every engine method, and because a hand implementation is a legitimate escape hatch for exotic layouts.

Required Associated Constants§

const TABLE_NAME: &'static str

Table name, used in diagnostics and error messages.

Required Associated Types§

type Key: Ord + Clone + Hash + Send + Sync + 'static

The primary key type, from the #[mvcc(primary_key)] field.

Required Methods§

fn table_id_cell() -> &'static OnceLock<TableId>

Storage for this type’s table id.

The derive emits a private static OnceLock<TableId> per type and returns it here; Database::register fills it in. A OnceLock rather than a const because ids are assigned in registration order, which is not known until runtime.

fn key(&self) -> Self::Key

Extract the primary key.

fn key_bytes(&self) -> IndexKey

The primary key in memcmp order, for the primary index.

fn indexes() -> &'static [IndexDesc<Self>]

Secondary indexes declared with #[mvcc(index)].

Provided Methods§

fn table_id() -> TableId

This type’s table id.

§Panics

If the type was never registered. This is a programming error rather than a runtime condition — every engine method that could reach it already requires a Database the caller had to register with.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§