#![deny(rustdoc::broken_intra_doc_links)]
#![warn(missing_docs)]
mod entry;
mod node_data;
mod tree;
mod version;
pub use entry::{Entry, MAX_ENTRY_SIZE};
pub use node_data::{NodeData, MAX_NODE_DATA_SIZE};
pub use tree::Tree;
pub use version::{Version, V1, V2};
#[derive(Debug)]
pub enum Error {
ExpectedInMemory(EntryLink),
ExpectedNode(Option<EntryLink>),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
Self::ExpectedInMemory(l) => write!(f, "Node/leaf expected to be in memory: {}", l),
Self::ExpectedNode(None) => write!(f, "Node expected"),
Self::ExpectedNode(Some(l)) => write!(f, "Node expected, not leaf: {}", l),
}
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub enum EntryLink {
Stored(u32),
Generated(u32),
}
impl std::fmt::Display for EntryLink {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
Self::Stored(v) => write!(f, "stored({})", v),
Self::Generated(v) => write!(f, "generated({})", v),
}
}
}
#[repr(C)]
#[derive(Debug)]
pub enum EntryKind {
Leaf,
Node(EntryLink, EntryLink),
}
impl Error {
pub fn link_node_expected(link: EntryLink) -> Self {
Self::ExpectedNode(Some(link))
}
pub fn node_expected() -> Self {
Self::ExpectedNode(None)
}
pub(crate) fn augment(self, link: EntryLink) -> Self {
match self {
Error::ExpectedNode(_) => Error::ExpectedNode(Some(link)),
val => val,
}
}
}