Skip to content

Commit d77cca2

Browse files
committed
introduce or strategy combinator
1 parent b7236ba commit d77cca2

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

  • libsql-wal/src/swap_strategy

libsql-wal/src/swap_strategy/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ pub(crate) trait SwapStrategy: Sync + Send + 'static {
1212
And(self, other)
1313
}
1414

15+
fn or<O: SwapStrategy>(self, other: O) -> Or<Self, O>
16+
where
17+
Self: Sized,
18+
{
19+
Or(self, other)
20+
}
21+
}
22+
1523
pub struct And<A, B>(A, B);
1624

1725
impl<A, B> SwapStrategy for And<A, B>
@@ -31,4 +39,21 @@ where
3139
}
3240
}
3341

42+
pub struct Or<A, B>(A, B);
43+
44+
impl<A, B> SwapStrategy for Or<A, B>
45+
where
46+
A: SwapStrategy,
47+
B: SwapStrategy,
48+
{
49+
#[inline(always)]
50+
fn should_swap(&self, frames_in_wal: usize) -> bool {
51+
self.0.should_swap(frames_in_wal) || self.1.should_swap(frames_in_wal)
52+
}
53+
54+
#[inline(always)]
55+
fn swapped(&self) {
56+
self.0.swapped();
57+
self.1.swapped();
58+
}
3459
}

0 commit comments

Comments
 (0)