diff --git a/radicle-crdt/src/change.rs b/radicle-crdt/src/change.rs
index 148fe2f9..27da448c 100644
--- a/radicle-crdt/src/change.rs
+++ b/radicle-crdt/src/change.rs
@@ -25,12 +25,14 @@ pub struct Change {
pub clock: LClock,
}
-impl<'de, A: Serialize + Deserialize<'de>> Change {
+impl Change {
/// Get the change id.
pub fn id(&self) -> ChangeId {
(self.clock, self.author)
}
+}
+impl Change {
/// Serialize the change into a byte string.
pub fn encode(&self) -> Vec {
let mut buf = Vec::new();
@@ -41,7 +43,9 @@ impl<'de, A: Serialize + Deserialize<'de>> Change {
buf
}
+}
+impl<'de, A: Deserialize<'de>> Change {
/// Deserialize a change from a byte string.
pub fn decode(bytes: &'de [u8]) -> Result {
serde_json::from_slice(bytes)
diff --git a/radicle-crdt/src/lwwreg.rs b/radicle-crdt/src/lwwreg.rs
index 86f9aa8c..ffdc39e2 100644
--- a/radicle-crdt/src/lwwreg.rs
+++ b/radicle-crdt/src/lwwreg.rs
@@ -1,3 +1,5 @@
+use num_traits::Bounded;
+
use crate::ord::Max;
use crate::Semilattice;
@@ -43,10 +45,28 @@ impl LWWReg {
}
}
+impl From for LWWReg {
+ fn from(value: T) -> Self {
+ Self {
+ clock: Max::from(C::default()),
+ value,
+ }
+ }
+}
+
+impl Default for LWWReg {
+ fn default() -> Self {
+ Self {
+ clock: Max::default(),
+ value: T::default(),
+ }
+ }
+}
+
impl Semilattice for LWWReg
where
- T: PartialOrd + Default + Semilattice,
- C: PartialOrd + Default,
+ T: PartialOrd + Semilattice,
+ C: PartialOrd,
{
fn merge(&mut self, other: Self) {
self.set(other.value, other.clock.into_inner());