Refactor to avoid a spurious compatibility warning
[anymap] / src / raw.rs
index dbd5e2cb120e2bf8700754ed87dfa925e7853da1..aa3d6dc7dd83b1d3e159339c5abd5c2abdee86d2 100644 (file)
@@ -10,6 +10,7 @@ use std::hash::{Hasher, BuildHasherDefault};
 #[cfg(test)]
 use std::mem;
 use std::ops::{Index, IndexMut};
+use std::ptr;
 
 use any::{Any, UncheckedAnyExt};
 
@@ -22,11 +23,10 @@ impl Hasher for TypeIdHasher {
     #[inline]
     fn write(&mut self, bytes: &[u8]) {
         // This expects to receive one and exactly one 64-bit value
-        assert!(bytes.len() == 8);
-        self.value = u64::from(bytes[0])       | u64::from(bytes[1]) << 8  |
-                     u64::from(bytes[2]) << 16 | u64::from(bytes[3]) << 24 |
-                     u64::from(bytes[4]) << 32 | u64::from(bytes[5]) << 40 |
-                     u64::from(bytes[6]) << 48 | u64::from(bytes[7]) << 56;
+        debug_assert!(bytes.len() == 8);
+        unsafe {
+            ptr::copy_nonoverlapping(&bytes[0] as *const u8 as *const u64, &mut self.value, 1)
+        }
     }
 
     #[inline]
@@ -56,7 +56,7 @@ fn type_id_hasher() {
 /// contents of an `Map`. However, because you will then be dealing with `Any` trait objects, it
 /// doesn’t tend to be so very useful. Still, if you need it, it’s here.
 #[derive(Debug)]
-pub struct RawMap<A: ?Sized + UncheckedAnyExt = Any> {
+pub struct RawMap<A: ?Sized + UncheckedAnyExt = dyn Any> {
     inner: HashMap<TypeId, Box<A>, BuildHasherDefault<TypeIdHasher>>,
 }