Skip to main content

elefant_tools/storage/
table_data.rs

1use crate::storage::data_format::DataFormat;
2use crate::Result;
3use std::future::Future;
4
5pub trait TableDataReader: Send {
6    fn read_chunk(&mut self) -> impl Future<Output = Result<Option<&[u8]>>> + '_;
7}
8
9/// Data in a table. This data can be read from the data source using the reader.
10///
11/// Make sure to call `cleanup` when you have read all the data from the reader.
12pub struct TableData<R: TableDataReader, C: AsyncCleanup> {
13    pub data: R,
14    pub data_format: DataFormat,
15    pub cleanup: C,
16}
17
18pub trait AsyncCleanup: Send {
19    fn cleanup(self) -> impl Future<Output = Result<()>>;
20}
21
22impl AsyncCleanup for () {
23    async fn cleanup(self) -> Result<()> {
24        Ok(())
25    }
26}
27
28impl<R: TableDataReader, C: AsyncCleanup> AsyncCleanup for TableData<R, C> {
29    fn cleanup(self) -> impl Future<Output = Result<()>> {
30        self.cleanup.cleanup()
31    }
32}