Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix package-scale compilation for subcrates, make ketrees generic over their hasher #560

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading