1
use super::PagedWriter;
2
use crate::{error::Error, ArcBytes};
3

            
4
/// A trait for serializing and deserializing from a tree.
5
pub trait BinarySerialization: Send + Sync + Sized {
6
    /// Serializes `self` into `writer`, using `paged_writer` to store any
7
    /// additional data as needed.
8
    fn serialize_to(
9
        &mut self,
10
        writer: &mut Vec<u8>,
11
        paged_writer: &mut PagedWriter<'_>,
12
    ) -> Result<usize, Error>;
13

            
14
    /// Deserialize an instance from `reader`. If an allocation of nodes is
15
    /// needed, assume `current_order` is the maximum number of nodes a node can
16
    /// contain.
17
    fn deserialize_from(
18
        reader: &mut ArcBytes<'_>,
19
        current_order: Option<usize>,
20
    ) -> Result<Self, Error>;
21
}
22

            
23
impl BinarySerialization for () {
24
    fn serialize_to(
25
        &mut self,
26
        _writer: &mut Vec<u8>,
27
        _paged_writer: &mut PagedWriter<'_>,
28
    ) -> Result<usize, Error> {
29
        Ok(0)
30
    }
31

            
32
    fn deserialize_from(
33
        _reader: &mut ArcBytes<'_>,
34
        _current_order: Option<usize>,
35
    ) -> Result<Self, Error> {
36
        Ok(())
37
    }
38
}