1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::{Canon, IdBuilder, Ident, Sink, Store};
pub struct DrySink<S: Store>(<S::Ident as Ident>::Builder);
impl<S: Store> DrySink<S> {
pub fn new() -> Self {
DrySink(<S::Ident as Ident>::Builder::default())
}
}
impl<S> Sink<S> for DrySink<S>
where
S: Store,
{
fn copy_bytes(&mut self, bytes: &[u8]) {
self.0.write_bytes(bytes)
}
fn recur<T>(&self, t: &T) -> Result<S::Ident, S::Error>
where
T: Canon<S>,
{
let mut sink = DrySink::new();
t.write(&mut sink)?;
Ok(sink.fin())
}
fn fin(self) -> S::Ident {
self.0.fin()
}
}