#![feature(coverage_attribute)]
#![deny(
clippy::correctness,
clippy::complexity,
clippy::perf,
clippy::missing_inline_in_public_items
)]
mod error;
mod hash;
mod mutree;
mod trie;
#[cfg(test)]
pub mod testing;
pub mod prelude {
pub use digest::Digest;
pub use crate::{
error::{Error, Result},
hash::Hash,
mutree::Mutree,
trie::{Neighbor, Proof, Step, Trie},
CmRDT,
CvRDT,
FromBytes,
FromHex,
ToBytes,
ToHex,
};
}
use digest::Digest;
use proptest::prelude::*;
use self::prelude::*;
pub trait CvRDT: Sized + Arbitrary + Default + Clone + PartialEq {
fn merge(&mut self, other: &Self) -> Result<(), Error>;
}
pub trait CmRDT<T>: Sized + Arbitrary + Default + Clone + PartialEq {
fn apply(&mut self, other: &T) -> Result<(), Error>;
}
pub trait FromBytes
where
Self: Sized,
{
fn from_bytes(bytes: &[u8]) -> Result<Self>;
}
pub trait ToBytes {
type Output: AsRef<[u8]>;
fn to_bytes(&self) -> Self::Output;
#[inline]
fn to_bytes_vec(&self) -> Vec<u8> {
self.to_bytes().as_ref().to_vec()
}
#[inline]
fn hash_bytes<D: Digest>(&self) -> crate::hash::Hash {
crate::hash::Hash::digest::<D>(self.to_bytes().as_ref())
}
#[inline]
fn is_zero(&self) -> bool {
let len = self.to_bytes().as_ref().len();
self.to_bytes_vec() == vec![0; len]
}
#[inline]
fn to_bytes_mut(&mut self) -> &mut [u8] {
unimplemented!("to_bytes_mut is not implemented for this type")
}
}
pub trait FromHex
where
Self: Sized,
{
fn from_hex(hex: &str) -> Result<Self>;
}
pub trait ToHex {
fn to_hex(&self) -> String;
}
#[cfg(test)]
pub mod __dependencies {
pub use paste;
pub use proptest;
pub use test_strategy;
}