//!
//! All relevant details are in the `RawMap` struct.
-use std::any::{Any, TypeId};
-use std::borrow::Borrow;
+use core::any::{Any, TypeId};
+use core::borrow::Borrow;
+#[cfg(all(feature = "std", not(feature = "hashbrown")))]
use std::collections::hash_map::{self, HashMap};
-use std::convert::TryInto;
-use std::hash::Hash;
-use std::hash::{Hasher, BuildHasherDefault};
-#[cfg(test)]
-use std::mem;
-use std::ops::{Index, IndexMut};
+#[cfg(feature = "hashbrown")]
+use hashbrown::hash_map::{self, HashMap};
+#[cfg(not(feature = "std"))]
+use alloc::boxed::Box;
+use core::convert::TryInto;
+use core::hash::Hash;
+use core::hash::{Hasher, BuildHasherDefault};
+use core::ops::{Index, IndexMut};
-use any::UncheckedAnyExt;
+use crate::any::UncheckedAnyExt;
#[derive(Default)]
struct TypeIdHasher {
#[test]
fn type_id_hasher() {
+ #[cfg(not(feature = "std"))]
+ use alloc::vec::Vec;
fn verify_hashing_with(type_id: TypeId) {
let mut hasher = TypeIdHasher::default();
type_id.hash(&mut hasher);
// SAFETY: u64 is valid for all bit patterns.
- assert_eq!(hasher.finish(), unsafe { mem::transmute::<TypeId, u64>(type_id) });
+ assert_eq!(hasher.finish(), unsafe { core::mem::transmute::<TypeId, u64>(type_id) });
}
// Pick a variety of types, just to demonstrate it’s all sane. Normal, zero-sized, unsized, &c.
verify_hashing_with(TypeId::of::<usize>());
/// A view into a single occupied location in a `RawMap`.
pub struct OccupiedEntry<'a, A: ?Sized + UncheckedAnyExt> {
+ #[cfg(all(feature = "std", not(feature = "hashbrown")))]
inner: hash_map::OccupiedEntry<'a, TypeId, Box<A>>,
+ #[cfg(feature = "hashbrown")]
+ inner: hash_map::OccupiedEntry<'a, TypeId, Box<A>, BuildHasherDefault<TypeIdHasher>>,
}
/// A view into a single empty location in a `RawMap`.
pub struct VacantEntry<'a, A: ?Sized + UncheckedAnyExt> {
+ #[cfg(all(feature = "std", not(feature = "hashbrown")))]
inner: hash_map::VacantEntry<'a, TypeId, Box<A>>,
+ #[cfg(feature = "hashbrown")]
+ inner: hash_map::VacantEntry<'a, TypeId, Box<A>, BuildHasherDefault<TypeIdHasher>>,
}
/// A view into a single location in a `RawMap`, which may be vacant or occupied.