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