elefant_tools/storage/
table_data.rs

1use crate::storage::data_format::DataFormat;
2use crate::Result;
3use bytes::Bytes;
4use futures::Stream;
5use std::future::Future;
6
7/// Data in a table. This data is a stream which can be read from the data source.
8///
9/// Make sure to call `cleanup` when you have read all the data from the stream.
10pub struct TableData<S: Stream<Item = Result<Bytes>> + Send, C: AsyncCleanup> {
11    pub data: S,
12    pub data_format: DataFormat,
13    pub cleanup: C,
14}
15
16pub trait AsyncCleanup: Send {
17    fn cleanup(self) -> impl Future<Output = Result<()>> + Send;
18}
19
20impl AsyncCleanup for () {
21    async fn cleanup(self) -> Result<()> {
22        Ok(())
23    }
24}
25
26impl<S: Stream<Item = Result<Bytes>> + Send, C: AsyncCleanup> AsyncCleanup for TableData<S, C> {
27    fn cleanup(self) -> impl Future<Output = Result<()>> + Send {
28        self.cleanup.cleanup()
29    }
30}