Skip to content

Commit

Permalink
fix package-scale compilation for subcrates, make ketrees generic ove…
Browse files Browse the repository at this point in the history
…r their hasher
  • Loading branch information
p-avital committed Oct 4, 2023
1 parent c6fec02 commit 28ad2d6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions commons/zenoh-keyexpr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 8 additions & 5 deletions commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@
// ZettaScale Zenoh Team, <[email protected]>
//

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},

Check failure on line 18 in commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs

View workflow job for this annotation

GitHub Actions / Run no_std checks

unresolved import `hashbrown::hash_map::DefaultHasher`

Check failure on line 18 in commons/zenoh-keyexpr/src/keyexpr_tree/impls/hashmap_impl.rs

View workflow job for this annotation

GitHub Actions / Run no_std checks

unresolved import `hashbrown::hash_map::DefaultHasher`
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<T: 'static> IChildrenProvider<T> for HashMapProvider {
type Assoc = HashMap<OwnedKeyExpr, T>;
pub struct HashMapProvider<Hash: Hasher + Default + 'static = DefaultHasher>(
core::marker::PhantomData<Hash>,
);
impl<T: 'static, Hash: Hasher + Default + 'static> IChildrenProvider<T> for HashMapProvider<Hash> {
type Assoc = HashMap<OwnedKeyExpr, T, core::hash::BuildHasherDefault<Hash>>;
}

#[cfg(not(feature = "std"))]
Expand Down
12 changes: 10 additions & 2 deletions commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@
// ZettaScale Zenoh Team, <[email protected]>
//

use core::hash::Hasher;
#[cfg(not(feature = "std"))]
use hashbrown::hash_map::DefaultHasher;

Check failure on line 17 in commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs

View workflow job for this annotation

GitHub Actions / Run no_std checks

unresolved import `hashbrown::hash_map::DefaultHasher`

Check failure on line 17 in commons/zenoh-keyexpr/src/keyexpr_tree/impls/keyed_set_impl.rs

View workflow job for this annotation

GitHub Actions / Run no_std checks

unresolved import `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<T: 'static> IChildrenProvider<T> for KeyedSetProvider {
pub struct KeyedSetProvider<Hash: Hasher + Default + 'static = DefaultHasher>(
core::marker::PhantomData<Hash>,
);
impl<T: 'static, Hash: Hasher + Default + 'static> IChildrenProvider<T> for KeyedSetProvider<Hash> {
type Assoc = KeyedSet<T, ChunkExtractor>;
}
#[derive(Debug, Default, Clone, Copy)]
Expand Down
3 changes: 2 additions & 1 deletion commons/zenoh-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
2 changes: 1 addition & 1 deletion commons/zenoh-protocol/src/network/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

*[
Expand Down

0 comments on commit 28ad2d6

Please sign in to comment.