aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorAlex Auvolat <lx@deuxfleurs.fr>2025-01-04 18:50:49 +0100
committerAlex Auvolat <lx@deuxfleurs.fr>2025-01-04 18:50:49 +0100
commit44ce6ae5b4c5b30a144d37aab1d11e7237a954c1 (patch)
treefa895fc1acd05244d96a68e443d8fe4ff6e33aaa /src/util
parent22487ceddfd3b8d0641601874e0f19143da38699 (diff)
downloadgarage-44ce6ae5b4c5b30a144d37aab1d11e7237a954c1.tar.gz
garage-44ce6ae5b4c5b30a144d37aab1d11e7237a954c1.zip
properly implement new bucket model using a migration
Diffstat (limited to 'src/util')
-rw-r--r--src/util/crdt/deletable.rs10
-rw-r--r--src/util/crdt/lww.rs10
2 files changed, 20 insertions, 0 deletions
diff --git a/src/util/crdt/deletable.rs b/src/util/crdt/deletable.rs
index e771aceb..0594d850 100644
--- a/src/util/crdt/deletable.rs
+++ b/src/util/crdt/deletable.rs
@@ -9,6 +9,16 @@ pub enum Deletable<T> {
Deleted,
}
+impl<T> Deletable<T> {
+ /// Map value, used for migrations
+ pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Deletable<U> {
+ match self {
+ Self::Present(x) => Deletable::<U>::Present(f(x)),
+ Self::Deleted => Deletable::<U>::Deleted,
+ }
+ }
+}
+
impl<T: Crdt> Deletable<T> {
/// Create a new deletable object that isn't deleted
pub fn present(v: T) -> Self {
diff --git a/src/util/crdt/lww.rs b/src/util/crdt/lww.rs
index 958844c9..2e5875ea 100644
--- a/src/util/crdt/lww.rs
+++ b/src/util/crdt/lww.rs
@@ -43,6 +43,16 @@ pub struct Lww<T> {
v: T,
}
+impl<T> Lww<T> {
+ /// Map value, used for migrations
+ pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Lww<U> {
+ Lww::<U> {
+ ts: self.ts,
+ v: f(self.v),
+ }
+ }
+}
+
impl<T> Lww<T>
where
T: Crdt,