use crate::{
node::{Node, NodePlan, Value},
ChildReference, MaybeDebug,
};
use crate::rstd::{borrow::Borrow, hash, vec::Vec, Error};
pub type Partial<'a> = ((u8, u8), &'a [u8]);
pub trait NodeCodec: Sized {
const ESCAPE_HEADER: Option<u8> = None;
type Error: Error;
type HashOut: AsRef<[u8]>
+ AsMut<[u8]>
+ Default
+ MaybeDebug
+ PartialEq
+ Eq
+ hash::Hash
+ Send
+ Sync
+ Clone
+ Copy;
fn hashed_null_node() -> Self::HashOut;
fn decode_plan(data: &[u8]) -> Result<NodePlan, Self::Error>;
fn decode<'a>(data: &'a [u8]) -> Result<Node<'a>, Self::Error> {
Ok(Self::decode_plan(data)?.build(data))
}
fn is_empty_node(data: &[u8]) -> bool;
fn empty_node() -> &'static [u8];
fn leaf_node(partial: impl Iterator<Item = u8>, number_nibble: usize, value: Value) -> Vec<u8>;
fn extension_node(
partial: impl Iterator<Item = u8>,
number_nibble: usize,
child_ref: ChildReference<Self::HashOut>,
) -> Vec<u8>;
fn branch_node(
children: impl Iterator<Item = impl Borrow<Option<ChildReference<Self::HashOut>>>>,
value: Option<Value>,
) -> Vec<u8>;
fn branch_node_nibbled(
partial: impl Iterator<Item = u8>,
number_nibble: usize,
children: impl Iterator<Item = impl Borrow<Option<ChildReference<Self::HashOut>>>>,
value: Option<Value>,
) -> Vec<u8>;
}