mace-kv 0.0.34

A fast, cross-platform embedded key-value storage engine with ACID, MVCC, and flash-optimized storage
Documentation
use crate::types::{
    header::BoxHeader,
    refbox::{BoxRef, BoxView},
};
use crate::utils::OpCode;
use crate::utils::data::Position;

pub trait ILoader {
    fn copy_detached(&self) -> Self;

    fn copy(&self) -> Self;

    fn pin(&self, data: BoxRef);

    fn load_pinned(&self, addr: u64) -> Result<BoxView, OpCode>;

    fn load_sibling(&self, addr: u64) -> Result<BoxRef, OpCode>;

    fn load_blob(&self, addr: u64, cache: bool) -> Result<BoxRef, OpCode>;
}

pub trait IAsBoxRef {
    fn as_box(&self) -> BoxRef;
}

pub trait IBoxHeader {
    fn box_header(&self) -> &BoxHeader;

    fn box_header_mut(&mut self) -> &mut BoxHeader;
}

pub trait IHeader<T> {
    fn header(&self) -> &T;

    fn header_mut(&mut self) -> &mut T;
}

pub trait IFrameAlloc {
    fn alloc(&mut self, size: u32) -> BoxRef;

    fn inline_size(&self) -> usize;

    fn checkpoint_lsn(&self, _group: u8) -> Position {
        Position::MIN
    }
}

pub trait IKey: Default + IKeyCodec + Ord {
    fn raw(&self) -> &[u8];

    fn txid(&self) -> u64;

    fn to_string(&self) -> String;
}

pub trait IDecode {
    fn decode_from(raw: &[u8]) -> Self;
}

pub trait ICodec: IDecode + Copy {
    fn packed_size(&self) -> usize;

    fn encode_to(&self, to: &mut [u8]);
}

pub trait IKeyCodec: ICodec {
    fn remove_prefix(&self, prefix_len: usize) -> Self;
}

pub trait IVal: ICodec + Clone {
    fn is_tombstone(&self) -> bool;
}

pub trait IAsSlice: Sized {
    fn as_slice(&self) -> &[u8] {
        let p = self as *const Self;
        unsafe { std::slice::from_raw_parts(p.cast(), size_of::<Self>()) }
    }

    fn from_slice(x: &[u8]) -> Self {
        assert!(x.len() >= size_of::<Self>());
        unsafe { std::ptr::read_unaligned(x.as_ptr().cast::<Self>()) }
    }

    fn len(&self) -> usize {
        size_of::<Self>()
    }
}