pub trait Slot {
const SIZE: usize;
const KEY_LEN: usize;
// Required methods
fn write(&self, out: &mut [u8]);
fn read(bytes: &[u8]) -> Self;
}Expand description
A fixed-size record that can be stored in an Arena.
The container itself only ever sees bytes — this trait is the entire typed surface. Type erasure is deliberate: the generic container code is instantiated once per slot size, not once per rich type, which keeps monomorphization (and therefore wasm binary size) small, and lets binary search and shifting operate on raw byte ranges.
§Layout contract
A slot is SIZE bytes: the first KEY_LEN bytes are the key prefix,
the rest is payload. Rules:
1 <= KEY_LEN <= SIZE <= PAGE_BYTES(4096) — checked atArena::new, violations returnError::BadSlot.- The key prefix must be order-preserving: byte-wise comparison of
two encoded keys must equal the intended ordering of the records.
Encode integers big-endian — use the
keyhelpers. writemust fill allSIZEbytes (the container never zeroes slots for you — see the crate-level notes on the uninitialized-page optimization);readmust be its inverse:read(write(x)) == x.
§Example
use plugmem_arena::{key, Slot};
/// An edge record: `[src | dst]` key, 4-byte payload.
struct Edge { src: u32, dst: u32, weight: u32 }
impl Slot for Edge {
const SIZE: usize = 12;
const KEY_LEN: usize = 8;
fn write(&self, out: &mut [u8]) {
key::write_u32(out, self.src);
key::write_u32(&mut out[4..], self.dst);
key::write_u32(&mut out[8..], self.weight);
}
fn read(bytes: &[u8]) -> Self {
Edge {
src: key::read_u32(bytes),
dst: key::read_u32(&bytes[4..]),
weight: key::read_u32(&bytes[8..]),
}
}
}Required Associated Constants§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<const N: usize> Slot for [u8; N]
Byte arrays are slots whose key is the whole value (set semantics) —
handy for id/hash sets, mirroring the first test version of this
structure which stored 20/32-byte identifiers.
impl<const N: usize> Slot for [u8; N]
Byte arrays are slots whose key is the whole value (set semantics) — handy for id/hash sets, mirroring the first test version of this structure which stored 20/32-byte identifiers.