use crate::rstd::vec::Vec;
#[cfg_attr(feature = "std", derive(Debug))]
#[derive(PartialEq, Eq, Clone)]
pub struct Record<HO> {
pub depth: u32,
pub data: Vec<u8>,
pub hash: HO,
}
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Recorder<HO> {
nodes: Vec<Record<HO>>,
min_depth: u32,
}
impl<HO: Copy> Default for Recorder<HO> {
fn default() -> Self {
Recorder::new()
}
}
impl<HO: Copy> Recorder<HO> {
#[inline]
pub fn new() -> Self {
Recorder::with_depth(0)
}
pub fn with_depth(depth: u32) -> Self {
Recorder {
nodes: Vec::new(),
min_depth: depth,
}
}
pub fn record(&mut self, hash: &HO, data: &[u8], depth: u32) {
if depth >= self.min_depth {
self.nodes.push(Record {
depth,
data: data.into(),
hash: *hash,
})
}
}
pub fn drain(&mut self) -> Vec<Record<HO>> {
crate::rstd::mem::replace(&mut self.nodes, Vec::new())
}
}