Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Merge a8f7a36 into eb81dc9
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-da committed Jan 21, 2021
2 parents eb81dc9 + a8f7a36 commit 9bb05d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Expand Up @@ -9,8 +9,9 @@ edition = "2018"

[dependencies]
crdt_tree = "0.0.8"
brb = "1.0.1"
brb = "1.0.2"
serde = "1.0.120"
thiserror = "1.0.23"

[dev-dependencies]
quickcheck = "1.0.3"
Expand Down
15 changes: 7 additions & 8 deletions src/brb_tree.rs
Expand Up @@ -4,6 +4,7 @@ use brb::BRBDataType;

use serde::Serialize;
use std::{fmt::Debug, hash::Hash};
use thiserror::Error;

/// BRBTRee is a BRBDataType wrapper around a Tree CRDT. (crdt_tree)
///
Expand Down Expand Up @@ -33,9 +34,10 @@ impl<A: Clone + Hash + Ord, ID: TreeId, M: TreeMeta> BRBTree<A, ID, M> {
}
}

#[derive(Debug, PartialEq, Eq)]
pub enum ValidationError<A> {
SourceNotSameAsOperator { source: A, op_actor: A },
#[derive(Error, Debug, PartialEq, Eq)]
pub enum ValidationError {
#[error("The source actor does not match the actor associated with the operation")]
SourceDoesNotMatchOp,
}

impl<
Expand All @@ -45,7 +47,7 @@ impl<
> BRBDataType<A> for BRBTree<A, ID, M>
{
type Op = OpMove<ID, M, A>;
type ValidationError = ValidationError<A>;
type ValidationError = ValidationError;

/// Create a new BRBTree
fn new(actor: A) -> Self {
Expand All @@ -58,10 +60,7 @@ impl<
/// Validate an operation.
fn validate(&self, source: &A, op: &Self::Op) -> Result<(), Self::ValidationError> {
if op.timestamp().actor_id() != source {
Err(ValidationError::SourceNotSameAsOperator {
source: source.clone(),
op_actor: op.timestamp().actor_id().clone(),
})
Err(ValidationError::SourceDoesNotMatchOp)
} else {
Ok(())
}
Expand Down

0 comments on commit 9bb05d3

Please sign in to comment.