refactor: Extract a type alias for the trait's error type
use async_trait::async_trait;
use entry::{Entry, Sequence};
+pub type WriteBufferError = Box<dyn std::error::Error + Sync + Send>;
+
/// A Write Buffer takes an `Entry` and returns `Sequence` data that facilitates reading entries
/// from the Write Buffer at a later time.
#[async_trait]
pub trait WriteBuffer: Sync + Send + std::fmt::Debug + 'static {
/// Send an `Entry` to the write buffer and return information that can be used to restore
/// entries at a later time.
- async fn store_entry(
- &self,
- entry: &Entry,
- ) -> Result<Sequence, Box<dyn std::error::Error + Sync + Send>>;
+ async fn store_entry(&self, entry: &Entry) -> Result<Sequence, WriteBufferError>;
// TODO: interface for restoring, will look something like:
// async fn restore_from(&self, sequence: &Sequence) -> Result<Stream<Entry>, Err>;
@@ -24,10 +23,7 @@ pub struct KafkaBuffer {
#[async_trait]
impl WriteBuffer for KafkaBuffer {
- async fn store_entry(
- &self,
- _entry: &Entry,
- ) -> Result<Sequence, Box<dyn std::error::Error + Sync + Send>> {
+ async fn store_entry(&self, _entry: &Entry) -> Result<Sequence, WriteBufferError> {
unimplemented!()
}
}
@@ -52,10 +48,7 @@ pub mod test_helpers {
#[async_trait]
impl WriteBuffer for MockBuffer {
- async fn store_entry(
- &self,
- entry: &Entry,
- ) -> Result<Sequence, Box<dyn std::error::Error + Sync + Send>> {
+ async fn store_entry(&self, entry: &Entry) -> Result<Sequence, WriteBufferError> {
let mut entries = self.entries.lock().unwrap();
let offset = entries.len() as u64;
entries.push(entry.clone());
