external_buffered_stream/
buffer.rs

1#[cfg(feature = "sled")]
2mod sled;
3#[cfg(feature = "sled")]
4pub use sled::ExternalBufferSled;
5
6#[cfg(feature = "queue")]
7mod queue;
8#[cfg(feature = "queue")]
9pub use queue::ExternalBufferQueue;
10
11use crate::Error;
12
13/// The external buffer here allow us to:
14///   - save items in an external perssistant storage to achieve crash save
15///     for data.
16///   - even with a in memory buffer, we can still implement a priority
17///     queue for push and shift actions.
18pub trait ExternalBuffer<T: Sized>: Send + Sync {
19    fn push(&self, item: T) -> Result<(), Error>; // to end of buffer
20
21    fn shift(&self) -> Result<Option<T>, Error>; // from head of buffer
22}