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

Commit

Permalink
Merge cdb5644 into d038c19
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrusu committed Jan 21, 2021
2 parents d038c19 + cdb5644 commit 0cfad03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Expand Up @@ -8,8 +8,9 @@ repository = "https://github.com/maidsafe/brb_dt_orswot"
edition = "2018"

[dependencies]
crdts = "5.0.0"
crdts = "5.1.0"
brb = "1.0.1"
thiserror = "1.0"
serde = "1.0.120"

[profile.test]
Expand Down
27 changes: 14 additions & 13 deletions src/brb_orswot.rs
Expand Up @@ -3,17 +3,17 @@ use std::collections::HashSet;
use std::{fmt::Debug, hash::Hash};

use brb::BRBDataType;

use crdts::{orswot, CmRDT};
use serde::Serialize;
use thiserror::Error;

#[derive(Debug, Serialize, PartialEq, Eq, Clone)]
pub struct BRBOrswot<A: Hash + Ord + Clone, M: Clone + Eq + Hash> {
actor: A,
orswot: orswot::Orswot<M, A>,
}

impl<A: Hash + Ord + Clone, M: Clone + Eq + Hash> BRBOrswot<A, M> {
impl<A: Hash + Ord + Clone + Debug, M: Clone + Eq + Hash> BRBOrswot<A, M> {
pub fn add(&self, member: M) -> orswot::Op<M, A> {
let add_ctx = self.orswot.read_ctx().derive_add_ctx(self.actor.clone());
self.orswot.add(member, add_ctx)
Expand Down Expand Up @@ -41,12 +41,16 @@ impl<A: Hash + Ord + Clone, M: Clone + Eq + Hash> BRBOrswot<A, M> {
}
}

#[derive(Debug, PartialEq, Eq)]
pub enum ValidationError<A: Hash + Ord + Clone> {
SourceDoesNotMatchOp { source: A, op_source: A },
RemoveOnlySupportedForOneElement,
#[derive(Error, Debug, PartialEq, Eq)]
pub enum ValidationError<E: std::error::Error + 'static> {
#[error("The source actor is not the same as the dot attached to the operation")]
SourceDoesNotMatchOp,
#[error("Attempted to remove more than one member, this is not currently supported")]
RemoveOnlySupportedForOneMember,
#[error("Attempt to remove a member that we have not seen yet")]
RemovingDataWeHaventSeenYet,
Orswot(<orswot::Orswot<(), A> as CmRDT>::Validation),
#[error(transparent)]
Orswot(#[from] E),
}

impl<
Expand All @@ -55,7 +59,7 @@ impl<
> BRBDataType<A> for BRBOrswot<A, M>
{
type Op = orswot::Op<M, A>;
type ValidationError = ValidationError<A>;
type ValidationError = ValidationError<<orswot::Orswot<M, A> as CmRDT>::Validation>;

fn new(actor: A) -> Self {
BRBOrswot {
Expand All @@ -72,17 +76,14 @@ impl<
match op {
orswot::Op::Add { dot, members: _ } => {
if &dot.actor != source {
Err(ValidationError::SourceDoesNotMatchOp {
source: source.clone(),
op_source: dot.actor.clone(),
})
Err(ValidationError::SourceDoesNotMatchOp)
} else {
Ok(())
}
}
orswot::Op::Rm { clock, members } => {
if members.len() != 1 {
Err(ValidationError::RemoveOnlySupportedForOneElement)
Err(ValidationError::RemoveOnlySupportedForOneMember)
} else if matches!(
clock.partial_cmp(&self.orswot.clock()),
None | Some(Ordering::Greater)
Expand Down

0 comments on commit 0cfad03

Please sign in to comment.