X-Git-Url: https://git.chrismorgan.info/anymap/blobdiff_plain/764038fe6e3f5a28270a874bce2561924a316a20..0a1c85f8655a71b995d228ed0c9496f732268c5b:/src/raw.rs diff --git a/src/raw.rs b/src/raw.rs index 5720086..081edd4 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -2,17 +2,20 @@ //! //! 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 { @@ -37,11 +40,13 @@ impl Hasher for 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::(type_id) }); + assert_eq!(hasher.finish(), unsafe { core::mem::transmute::(type_id) }); } // Pick a variety of types, just to demonstrate it’s all sane. Normal, zero-sized, unsized, &c. verify_hashing_with(TypeId::of::()); @@ -262,12 +267,18 @@ impl IntoIterator for RawMap { /// 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>, + #[cfg(feature = "hashbrown")] + inner: hash_map::OccupiedEntry<'a, TypeId, Box, BuildHasherDefault>, } /// 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>, + #[cfg(feature = "hashbrown")] + inner: hash_map::VacantEntry<'a, TypeId, Box, BuildHasherDefault>, } /// A view into a single location in a `RawMap`, which may be vacant or occupied.