1#![deny(rustdoc::broken_intra_doc_links)]
7#![warn(missing_docs)]
8
9mod entry;
10mod node_data;
11mod tree;
12mod version;
13
14#[cfg(test)]
15mod test_vectors;
16
17pub use entry::{Entry, MAX_ENTRY_SIZE};
18pub use node_data::{MAX_NODE_DATA_SIZE, NodeData, V2 as NodeDataV2, V3 as NodeDataV3};
19pub use tree::Tree;
20pub use version::{V1, V2, V3, Version};
21
22#[derive(Debug)]
24pub enum Error {
25 ExpectedInMemory(EntryLink),
27 ExpectedNode(Option<EntryLink>),
29}
30
31impl std::fmt::Display for Error {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 match *self {
34 Self::ExpectedInMemory(l) => write!(f, "Node/leaf expected to be in memory: {l}"),
35 Self::ExpectedNode(None) => write!(f, "Node expected"),
36 Self::ExpectedNode(Some(l)) => write!(f, "Node expected, not leaf: {l}"),
37 }
38 }
39}
40
41#[repr(C)]
43#[derive(Clone, Copy, Debug)]
44pub enum EntryLink {
45 Stored(u32),
47 Generated(u32),
49}
50
51impl std::fmt::Display for EntryLink {
52 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53 match *self {
54 Self::Stored(v) => write!(f, "stored({v})"),
55 Self::Generated(v) => write!(f, "generated({v})"),
56 }
57 }
58}
59
60#[repr(C)]
62#[derive(Debug)]
63pub enum EntryKind {
64 Leaf,
66 Node(EntryLink, EntryLink),
68}
69
70impl Error {
71 pub fn link_node_expected(link: EntryLink) -> Self {
73 Self::ExpectedNode(Some(link))
74 }
75
76 pub fn node_expected() -> Self {
78 Self::ExpectedNode(None)
79 }
80
81 pub(crate) fn augment(self, link: EntryLink) -> Self {
82 match self {
83 Error::ExpectedNode(_) => Error::ExpectedNode(Some(link)),
84 val => val,
85 }
86 }
87}