From 28ad2d6959c1223a6bf0921133d1226bbc2ab05c Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Wed, 4 Oct 2023 11:44:48 +0200 Subject: [PATCH] fix package-scale compilation for subcrates, make ketrees generic over their hasher --- commons/zenoh-keyexpr/Cargo.toml | 1 + .../src/keyexpr_tree/impls/hashmap_impl.rs | 13 ++++++++----- .../src/keyexpr_tree/impls/keyed_set_impl.rs | 12 ++++++++++-- commons/zenoh-protocol/Cargo.toml | 3 ++- commons/zenoh-protocol/src/network/request.rs | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/commons/zenoh-keyexpr/Cargo.toml b/commons/zenoh-keyexpr/Cargo.toml index e9d37e9762..920db98696 100644 --- a/commons/zenoh-keyexpr/Cargo.toml +++ b/commons/zenoh-keyexpr/Cargo.toml @@ -42,6 +42,7 @@ hashbrown = { workspace = true } [dev-dependencies] criterion = { workspace = true } lazy_static = { workspace = true } +rand = { workspace = true, features = ["default"] } [[bench]] name = "keyexpr_tree" diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs index e446f82de1..f9bcdf799f 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs @@ -12,22 +12,25 @@ // ZettaScale Zenoh Team, // +use core::hash::Hasher; #[cfg(not(feature = "std"))] use hashbrown::{ - hash_map::{Entry, Iter, IterMut, Values, ValuesMut}, + hash_map::{DefaultHasher, Entry, Iter, IterMut, Values, ValuesMut}, HashMap, }; #[cfg(feature = "std")] use std::collections::{ - hash_map::{Entry, Iter, IterMut, Values, ValuesMut}, + hash_map::{DefaultHasher, Entry, Iter, IterMut, Values, ValuesMut}, HashMap, }; use crate::keyexpr_tree::*; -pub struct HashMapProvider; -impl IChildrenProvider for HashMapProvider { - type Assoc = HashMap; +pub struct HashMapProvider( + core::marker::PhantomData, +); +impl IChildrenProvider for HashMapProvider { + type Assoc = HashMap>; } #[cfg(not(feature = "std"))] diff --git a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs index 3e77a1de76..90fddd45ae 100644 --- a/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs +++ b/commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs @@ -12,11 +12,19 @@ // ZettaScale Zenoh Team, // +use core::hash::Hasher; +#[cfg(not(feature = "std"))] +use hashbrown::hash_map::DefaultHasher; +#[cfg(feature = "std")] +use std::collections::hash_map::DefaultHasher; + use crate::keyexpr_tree::*; use keyed_set::{KeyExtractor, KeyedSet}; -pub struct KeyedSetProvider; -impl IChildrenProvider for KeyedSetProvider { +pub struct KeyedSetProvider( + core::marker::PhantomData, +); +impl IChildrenProvider for KeyedSetProvider { type Assoc = KeyedSet; } #[derive(Debug, Default, Clone, Copy)] diff --git a/commons/zenoh-protocol/Cargo.toml b/commons/zenoh-protocol/Cargo.toml index 829c275804..07c11cb2fc 100644 --- a/commons/zenoh-protocol/Cargo.toml +++ b/commons/zenoh-protocol/Cargo.toml @@ -47,10 +47,11 @@ rand = { workspace = true, features = ["alloc", "getrandom"], optional = true } serde = { workspace = true, features = ["alloc"] } uhlc = { workspace = true, default-features = false } uuid = { workspace = true } # Needs a getrandom::getrandom() custom implementation on embedded (in root crate) -zenoh-buffers = { workspace = true, default-features = false } +zenoh-buffers = { workspace = true, default-features = false } zenoh-keyexpr = { workspace = true } zenoh-result = { workspace = true } # NOTE: May cause problems when testing no_std stuff. Check this tool: https://docs.rs/crate/cargo-no-dev-deps/0.1.0 [dev-dependencies] lazy_static = { workspace = true } +rand = { workspace = true, features = ["default"] } diff --git a/commons/zenoh-protocol/src/network/request.rs b/commons/zenoh-protocol/src/network/request.rs index 17bab1905d..9e0137ea3a 100644 --- a/commons/zenoh-protocol/src/network/request.rs +++ b/commons/zenoh-protocol/src/network/request.rs @@ -93,7 +93,7 @@ pub mod ext { impl TargetType { #[cfg(feature = "test")] pub fn rand() -> Self { - use rand::prelude::SliceRandom; + use rand::prelude::*; let mut rng = rand::thread_rng(); *[