Skip to content

Commit b7236ba

Browse files
committed
introduce And swap_strategy combinator
1 parent 0622523 commit b7236ba

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

  • libsql-wal/src/swap_strategy

libsql-wal/src/swap_strategy/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,31 @@ pub(crate) mod frame_count;
44
pub(crate) trait SwapStrategy: Sync + Send + 'static {
55
fn should_swap(&self, frames_in_wal: usize) -> bool;
66
fn swapped(&self);
7+
8+
fn and<O: SwapStrategy>(self, other: O) -> And<Self, O>
9+
where
10+
Self: Sized,
11+
{
12+
And(self, other)
13+
}
14+
15+
pub struct And<A, B>(A, B);
16+
17+
impl<A, B> SwapStrategy for And<A, B>
18+
where
19+
A: SwapStrategy,
20+
B: SwapStrategy,
21+
{
22+
#[inline(always)]
23+
fn should_swap(&self, frames_in_wal: usize) -> bool {
24+
self.0.should_swap(frames_in_wal) && self.1.should_swap(frames_in_wal)
25+
}
26+
27+
#[inline(always)]
28+
fn swapped(&self) {
29+
self.0.swapped();
30+
self.1.swapped();
31+
}
32+
}
33+
734
}

0 commit comments

Comments
 (0)