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

Enable cloning EntityHashMap and PreHashMap #11178

Merged
Merged
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
24 changes: 22 additions & 2 deletions crates/bevy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<V: Clone, H> Clone for Hashed<V, H> {
impl<V: Eq, H> Eq for Hashed<V, H> {}

/// A [`BuildHasher`] that results in a [`PassHasher`].
#[derive(Default)]
#[derive(Default, Clone)]
pub struct PassHash;

impl BuildHasher for PassHash {
Expand Down Expand Up @@ -251,7 +251,7 @@ impl<K: Hash + Eq + PartialEq + Clone, V> PreHashMapExt<K, V> for PreHashMap<K,
}

/// A [`BuildHasher`] that results in a [`EntityHasher`].
#[derive(Default)]
#[derive(Default, Clone)]
pub struct EntityHash;

impl BuildHasher for EntityHash {
Expand Down Expand Up @@ -415,3 +415,23 @@ macro_rules! detailed_trace {
}
}
}


#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_clone_entity_hash_map() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty partial to having something similar to static_assertions (it's already in our dependency tree), which includes a assertion that will fail compilation if a type does not implement a trait. I think it should be fine to use it as a dev dependency over these tests which actually need to run when running our test suites.

This is a strict non-blocker and we can tackle this in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah i was thinking of re-using trybuild (https://docs.rs/trybuild/latest/trybuild/) since I see that it's already used in bevy somewhere else, but static_assertions seems to have more powerful checks

let map = EntityHashMap::<u64, usize>::default();
// This should compile
let _ = map.clone();
}

#[test]
fn test_clone_pre_hash_map() {
let map = PreHashMap::<u64, usize>::default();
// This should compile
let _ = map.clone();
}
}
Loading