use crate::MaybeDebug;
use crate::node::{Node, NodePlan};
use crate::ChildReference;
use crate::rstd::{borrow::Borrow, Error, hash, vec::Vec};
pub type Partial<'a> = ((u8, u8), &'a[u8]);
pub trait NodeCodec: Sized {
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(data: &[u8]) -> Result<Node, 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: Partial, value: &[u8]) -> 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<&[u8]>,
) -> 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<&[u8]>
) -> Vec<u8>;
}