bevy_reflect/impls/bevy_platform/collections/
hash_map.rs1use bevy_reflect_derive::impl_type_path;
2
3use crate::impls::macros::impl_reflect_for_hashmap;
4#[cfg(feature = "functions")]
5use crate::{
6 from_reflect::FromReflect, type_info::MaybeTyped, type_path::TypePath,
7 type_registry::GetTypeRegistration,
8};
9#[cfg(feature = "functions")]
10use core::hash::{BuildHasher, Hash};
11
12impl_reflect_for_hashmap!(bevy_platform::collections::HashMap<K, V, S>);
13impl_type_path!(::bevy_platform::collections::HashMap<K, V, S>);
14#[cfg(feature = "functions")]
15crate::func::macros::impl_function_traits!(::bevy_platform::collections::HashMap<K, V, S>;
16 <
17 K: FromReflect + MaybeTyped + TypePath + GetTypeRegistration + Eq + Hash,
18 V: FromReflect + MaybeTyped + TypePath + GetTypeRegistration,
19 S: TypePath + BuildHasher + Default + Send + Sync
20 >
21);
22
23#[cfg(test)]
24mod tests {
25 use crate::{PartialReflect, Reflect};
26 use static_assertions::assert_impl_all;
27
28 #[test]
29 fn should_partial_eq_hash_map() {
30 let mut a = <bevy_platform::collections::HashMap<_, _>>::default();
31 a.insert(0usize, 1.23_f64);
32 let b = a.clone();
33 let mut c = <bevy_platform::collections::HashMap<_, _>>::default();
34 c.insert(0usize, 3.21_f64);
35
36 let a: &dyn PartialReflect = &a;
37 let b: &dyn PartialReflect = &b;
38 let c: &dyn PartialReflect = &c;
39 assert!(a.reflect_partial_eq(b).unwrap_or_default());
40 assert!(!a.reflect_partial_eq(c).unwrap_or_default());
41 }
42
43 #[test]
44 fn should_reflect_hashmaps() {
45 assert_impl_all!(bevy_platform::collections::HashMap<u32, f32>: Reflect);
46 }
47}