1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Defines the Allocator trait for StackDB

use std::io::{Read, Seek, Write};
use crate::{base::layer::Layer, errors::Error};

/// The allocator for a StackDB that defines how or where the layers are stored and managed
pub trait Allocator<'l> {
    /// The type of data stream the layers read and write to
    type LayerStream: Write + Read + Seek;
    /// Loads all the read-only layers in the database as `Layers`
    fn load_layers(&self) -> Result<Vec<Layer<'l, Self::LayerStream>>, Error>;
    /// Adds a read-write layer to the database
    fn add_layer(&mut self) -> Result<Layer<'l, Self::LayerStream>, Error>;
    /// Removes the top layer from the database
    fn drop_top_layer(&mut self) -> Result<(), Error>;
    /// Removes the bottom layer from the database
    fn drop_bottom_layer(&mut self) -> Result<(), Error>;
 }