stack_db/base/database/
allocator.rs

1//! Defines the Allocator trait for StackDB
2
3use std::io::{Read, Seek, Write};
4use crate::{base::layer::Layer, errors::Error};
5
6/// The allocator for a StackDB that defines how or where the layers are stored and managed
7pub trait Allocator<'l> {
8    /// The type of data stream the layers read and write to
9    type LayerStream: Write + Read + Seek;
10    /// Loads all the read-only layers in the database as `Layers`
11    fn load_layers(&self) -> Result<Vec<Layer<'l, Self::LayerStream>>, Error>;
12    /// Adds a read-write layer to the database
13    fn add_layer(&mut self) -> Result<Layer<'l, Self::LayerStream>, Error>;
14    /// Removes the top layer from the database
15    fn drop_top_layer(&mut self) -> Result<(), Error>;
16    /// Removes all the bottom layers except for the one specified (and above)
17    fn rebase(&mut self, top_layer: usize) -> Result<(), Error>;
18 }