use std::future::Future; /// Journal of operations used by a [super::Database] pub trait Journal: Send { /// The type of operations in the journal type Op: Send; /// The error type returned by the journal type Error: std::error::Error + Send + 'static + Into; /// Persist the journal. fn sync(&mut self) -> impl Future> + Send; /// Get the number of operations in the journal fn size(&self) -> impl Future + Send; /// Append an operation to the journal fn append(&mut self, op: Self::Op) -> impl Future> + Send; } impl Journal for crate::journal::contiguous::variable::Journal where E: commonware_runtime::Storage + commonware_runtime::Metrics, V: commonware_codec::CodecShared, { type Op = V; type Error = crate::journal::Error; async fn sync(&mut self) -> Result<(), Self::Error> { Self::sync(self).await } async fn size(&self) -> u64 { Self::size(self) } async fn append(&mut self, op: Self::Op) -> Result<(), Self::Error> { Self::append(self, op).await.map(|_| ()) } } impl Journal for crate::journal::contiguous::fixed::Journal where E: commonware_runtime::Storage + commonware_runtime::Metrics, A: commonware_codec::CodecFixedShared, { type Op = A; type Error = crate::journal::Error; async fn sync(&mut self) -> Result<(), Self::Error> { Self::sync(self).await } async fn size(&self) -> u64 { Self::size(self) } async fn append(&mut self, op: Self::Op) -> Result<(), Self::Error> { Self::append(self, op).await.map(|_| ()) } }