From 7e8af47f59e5362c424dcd5cb9d075bd6a4a650a Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Thu, 24 Nov 2022 19:13:34 +0100 Subject: [PATCH] Implement `Change::decode` Signed-off-by: Alexis Sellier --- radicle-crdt/src/thread.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/radicle-crdt/src/thread.rs b/radicle-crdt/src/thread.rs index 71b2cb70..d0b211e1 100644 --- a/radicle-crdt/src/thread.rs +++ b/radicle-crdt/src/thread.rs @@ -53,6 +53,11 @@ impl Change { buf } + + /// Deserialize a change from a byte string. + pub fn decode(bytes: &[u8]) -> Result { + serde_json::from_slice(bytes) + } } /// Change envelope. Carries signed changes. @@ -472,7 +477,7 @@ mod tests { let actual: Thread = retrieved .history() .traverse(Thread::default(), |mut acc, entry| { - let change: Change = serde_json::from_slice(entry.contents()).unwrap(); + let change = Change::decode(entry.contents()).unwrap(); acc.apply([change]); ControlFlow::Continue(acc)