wasmer_journal/concrete/
recombined.rs

1use super::*;
2
3#[derive(Debug)]
4pub struct RecombinedJournal<W: WritableJournal, R: ReadableJournal> {
5    tx: W,
6    rx: R,
7}
8
9impl<W: WritableJournal, R: ReadableJournal> RecombinedJournal<W, R> {
10    pub fn new(tx: W, rx: R) -> Self {
11        Self { tx, rx }
12    }
13}
14
15impl<W: WritableJournal, R: ReadableJournal> WritableJournal for RecombinedJournal<W, R> {
16    fn write<'a>(&'a self, entry: JournalEntry<'a>) -> anyhow::Result<LogWriteResult> {
17        self.tx.write(entry)
18    }
19
20    fn flush(&self) -> anyhow::Result<()> {
21        self.tx.flush()
22    }
23
24    fn commit(&self) -> anyhow::Result<usize> {
25        self.tx.commit()
26    }
27
28    fn rollback(&self) -> anyhow::Result<usize> {
29        self.tx.rollback()
30    }
31}
32
33impl<W: WritableJournal, R: ReadableJournal> ReadableJournal for RecombinedJournal<W, R> {
34    fn read(&self) -> anyhow::Result<Option<LogReadResult<'_>>> {
35        self.rx.read()
36    }
37
38    fn as_restarted(&self) -> anyhow::Result<Box<DynReadableJournal>> {
39        self.rx.as_restarted()
40    }
41}
42
43impl<W, R> Journal for RecombinedJournal<W, R>
44where
45    W: WritableJournal + Send + Sync + 'static,
46    R: ReadableJournal + Send + Sync + 'static,
47{
48    fn split(self) -> (Box<DynWritableJournal>, Box<DynReadableJournal>) {
49        (Box::new(self.tx), Box::new(self.rx))
50    }
51}