parasol_db/
lib.rs

1pub mod index;
2pub mod table;
3pub mod view;
4
5use std::iter::DoubleEndedIterator;
6
7pub type Seq = u64;
8
9pub trait View {
10    type Event;
11    type Iterator: DoubleEndedIterator<Item = (Seq, Self::Event)>;
12
13    /// Scan the view for events between the given sequences. Returns an double-ended iterator over the events. No work
14    /// is done until the iterator is consumed.
15    fn scan(&mut self, start_exclusive: Seq, end_inclusive: Seq) -> Self::Iterator;
16
17    /// Returns the current sequence number of the view. All new events will have a sequence number greater than this.
18    fn get_current_seq(&mut self) -> Seq;
19}
20
21pub trait Table: View {
22    /// Write the given events to the table. Returns the sequence numbers assigned, in order.
23    fn append<Iter: IntoIterator<Item = Self::Event>>(&mut self, events: Iter) -> Vec<Seq>;
24
25    /// Sets the current sequence number of the table unless its sequence number is already greater.
26    fn set_current_seq(&mut self, seq: Seq);
27}
28
29pub trait Index {
30    type Source: View;
31
32    /// Incorporates all changes up to and including the given sequence number into the index.
33    fn update(&mut self, source: &mut Self::Source, seq: Seq);
34
35    /// Returns the sequence number for which all changes up to and including it have been incorporated into the index.
36    fn get_current_seq(&self) -> Seq;
37}