Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
HatemMn committed Dec 27, 2024
1 parent e535dd7 commit 45839c2
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 73 deletions.
4 changes: 4 additions & 0 deletions src/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub trait IndexADT<Keyword: Send + Sync + Hash, Value: Send + Sync + Hash> {
) -> impl Send + Future<Output = Result<(), Self::Error>>;
}

#[allow(clippy::redundant_pub_crate)] // false positive. Used in ovec.rs and findex.rs.
pub(crate) trait VectorADT: Send + Sync {
/// Vectors are homogeneous.
type Value: Send + Sync;
Expand Down Expand Up @@ -84,6 +85,7 @@ pub trait MemoryADT {
#[cfg(test)]
pub mod tests {

#[allow(clippy::redundant_pub_crate)] // false positive. Used in ovec.rs.
pub(crate) use vector::*;

mod vector {
Expand All @@ -98,6 +100,7 @@ pub mod tests {

/// Adding information from different copies of the same vector should
/// be visible by all copies.
#[allow(clippy::redundant_pub_crate)] // false positive. Used in ovec.rs.
pub(crate) async fn test_vector_sequential<const LENGTH: usize>(
v: &(impl Clone + VectorADT<Value = [u8; LENGTH]>),
) {
Expand All @@ -116,6 +119,7 @@ pub mod tests {

/// Concurrently adding data to instances of the same vector should not
/// introduce data loss.
#[allow(clippy::redundant_pub_crate)] // false positive. Used in ovec.rs.
pub(crate) async fn test_vector_concurrent<
const LENGTH: usize,
V: 'static + Clone + VectorADT<Value = [u8; LENGTH]>,
Expand Down
2 changes: 1 addition & 1 deletion src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub enum Op {
Delete,
}

pub(crate) enum Mode {
enum Mode {
EqBlock(usize),
Offset(usize),
}
Expand Down
2 changes: 1 addition & 1 deletion src/encryption_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ mod tests {
use crate::{
address::Address,
encryption_layer::{MemoryEncryptionLayer, ADDRESS_LENGTH},
mem::InMemory,
memory::in_memory::InMemory,
secret::Secret,
symmetric_key::SymmetricKey,
MemoryADT,
Expand Down
34 changes: 0 additions & 34 deletions src/findex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,38 +270,4 @@ mod tests {
res
);
}

// #[tokio::test]
// async fn redis_TEST_HATEM() {
// let mut rng = ChaChaRng::from_entropy();
// let seed = Secret::random(&mut rng);
// const TEST_ADR_WORD_LENGTH: usize = 16;
// let memory =
// RedisMemory::<Address<TEST_ADR_WORD_LENGTH>, [u8; TEST_ADR_WORD_LENGTH]>::connect(
// "redis://localhost:6379",
// )
// .await
// .unwrap();
// let findex = Findex::new(seed, memory, dummy_encode::<WORD_LENGTH, _>, dummy_decode);
// let bindings = HashMap::<&str, HashSet<Value>>::from_iter([
// (
// "cat",
// HashSet::from_iter([Value::from(1), Value::from(3), Value::from(5)]),
// ),
// (
// "dog",
// HashSet::from_iter([Value::from(0), Value::from(2), Value::from(4)]),
// ),
// ]);
// findex.insert(bindings.clone().into_iter()).await.unwrap();
// let res = findex.search(bindings.keys().cloned()).await.unwrap();
// assert_eq!(bindings, res);

// findex.delete(bindings.clone().into_iter()).await.unwrap();
// let res = findex.search(bindings.keys().cloned()).await.unwrap();
// assert_eq!(
// HashMap::from_iter([("cat", HashSet::new()), ("dog", HashSet::new())]),
// res
// );
// }
}
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@ pub use encoding::{dummy_decode, dummy_encode};
pub use encoding::{Op, WORD_LENGTH};
pub use error::Error;
pub use findex::Findex;
pub use memory::memory as mem;
pub use secret::Secret;
#[cfg(test)]
pub use test::memory::{
test_guarded_write_concurrent, test_single_write_and_read, test_wrong_guard,
};
pub use value::Value;

// #[cfg(any(test, feature = "bench"))]
// mod memory;
#[cfg(feature = "bench")]
pub use mem::InMemory;
pub use crate::memory::in_memory::InMemory;

#[cfg(feature = "redis-mem")]
pub use crate::memory::{error::MemoryError, redis::RedisMemory};
/// 16-byte addresses ensure a high collision resistance that poses virtually no limitation on the
/// index.
///
Expand Down
8 changes: 4 additions & 4 deletions src/memory/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use core::fmt::Display;
#[cfg(feature = "redis-mem")]
use redis::RedisError;

#[cfg(any(test, feature = "bench"))]
#[cfg(test)]
use super::in_memory::InMemoryError;

#[derive(Debug)]
pub enum MemoryError {
#[cfg(any(test, feature = "bench"))]
#[cfg(test)]
InMemory(InMemoryError),
#[cfg(feature = "redis-mem")]
Redis(RedisError),
Expand All @@ -17,11 +17,11 @@ pub enum MemoryError {
impl Display for MemoryError {
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
#[cfg(any(test, feature = "bench"))]
#[cfg(test)]
Self::InMemory(err) => write!(_f, "in_memory: {err}"),
#[cfg(feature = "redis-mem")]
Self::Redis(err) => write!(_f, "redis: {err}"),
#[cfg(not(any(test, feature = "bench", feature = "redis-mem")))]
#[cfg(all(not(test), not(feature = "redis-mem")))]
_ => panic!("no other variant"),
}
}
Expand Down
9 changes: 0 additions & 9 deletions src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,3 @@ pub mod redis;

#[cfg(any(test, feature = "bench"))]
pub mod in_memory;

pub mod memory {
#[cfg(any(test, feature = "bench", feature = "redis-mem"))]
pub use crate::memory::error::MemoryError;
#[cfg(any(test, feature = "bench"))]
pub use crate::memory::in_memory::InMemory;
#[cfg(feature = "redis-mem")]
pub use crate::memory::redis::RedisMemory;
}
21 changes: 10 additions & 11 deletions src/memory/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ return value

#[derive(Clone)]
pub struct RedisMemory<Address, Word> {
pub manager: ConnectionManager, // is Send + Sync : https://docs.rs/redis/latest/redis/aio/struct.ConnectionManager.html#impl-Send-for-ConnectionManager
script_hash: String, // trivially Send + Sync
a: PhantomData<Address>, // is send + Sync because the underlying address we will use in findex is Send + Sync ([u8; ADDRESS_LENGTH])
w: PhantomData<Word>, // same as above
pub manager: ConnectionManager,
script_hash: String,
a: PhantomData<Address>,
w: PhantomData<Word>,
}

impl<Address, Word> fmt::Debug for RedisMemory<Address, Word> {
Expand All @@ -42,7 +42,7 @@ impl<Address, Word> fmt::Debug for RedisMemory<Address, Word> {
}
}

impl<Address, Word> RedisMemory<Address, Word> {
impl<Address: Sync, Word: Sync> RedisMemory<Address, Word> {
/// Connects to a Redis server with a `ConnectionManager`.
pub async fn connect_with_manager(manager: ConnectionManager) -> Result<Self, MemoryError> {
Ok(Self {
Expand Down Expand Up @@ -126,12 +126,11 @@ mod tests {
};
use serial_test::serial;

pub(crate) fn get_redis_url() -> String {
if let Ok(var_env) = std::env::var("REDIS_HOST") {
format!("redis://{var_env}:6379")
} else {
"redis://localhost:6379".to_owned()
}
fn get_redis_url() -> String {
std::env::var("REDIS_HOST").map_or_else(
|_| "redis://localhost:6379".to_owned(),
|var_env| format!("redis://{var_env}:6379"),
)
}

const WORD_LENGTH: usize = 16;
Expand Down
1 change: 1 addition & 0 deletions src/ovec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl TryFrom<&[u8]> for Header {
}

/// Implementation of a vector in an infinite array.
#[allow(clippy::redundant_pub_crate)] // false positive. Used in findex file.
#[derive(Debug)]
pub(crate) struct IVec<
const WORD_LENGTH: usize,
Expand Down
18 changes: 9 additions & 9 deletions src/test/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use crate::MemoryADT;

pub async fn test_single_write_and_read<T>(memory: &T, seed: [u8; 32])
where
T: MemoryADT,
T::Address: std::fmt::Debug + PartialEq + From<[u8; 16]>,
T::Word: std::fmt::Debug + PartialEq + From<[u8; 16]>,
T::Error: std::error::Error,
T: MemoryADT + Send + Sync,
T::Address: std::fmt::Debug + PartialEq + From<[u8; 16]> + Send,
T::Word: std::fmt::Debug + PartialEq + From<[u8; 16]> + Send,
T::Error: std::error::Error + Send,
{
let mut rng = StdRng::from_seed(seed);

Expand Down Expand Up @@ -60,10 +60,10 @@ where

pub async fn test_wrong_guard<T>(memory: &T, seed: [u8; 32])
where
T: MemoryADT,
T::Address: std::fmt::Debug + PartialEq + From<[u8; 16]>,
T::Word: std::fmt::Debug + PartialEq + From<[u8; 16]>,
T::Error: std::error::Error,
T: MemoryADT + Send + Sync,
T::Address: std::fmt::Debug + PartialEq + From<[u8; 16]> + Send,
T::Word: std::fmt::Debug + PartialEq + From<[u8; 16]> + Send,
T::Error: std::error::Error + Send,
{
let mut rng = StdRng::from_seed(seed);
let random_address = rng.gen::<u128>().to_be_bytes();
Expand Down Expand Up @@ -120,7 +120,7 @@ where

pub async fn test_guarded_write_concurrent<T>(memory: &T, seed: [u8; 32])
where
T: MemoryADT + Send + 'static + Clone,
T: MemoryADT + Send + Sync + 'static + Clone,
T::Address: std::fmt::Debug + PartialEq + From<[u8; 16]> + Send,
T::Word: std::fmt::Debug + PartialEq + From<[u8; 16]> + Into<[u8; 16]> + Send + Clone + Default,
T::Error: std::error::Error,
Expand Down
2 changes: 2 additions & 0 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#[allow(clippy::redundant_pub_crate)] // false positive. Used in tests.
#[cfg(test)]
pub(crate) mod memory;

0 comments on commit 45839c2

Please sign in to comment.