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