+#![cfg_attr(not(feature = "std"), no_std)]
+
+use core::convert::TryInto;
+use core::hash::Hasher;
+
+#[cfg(not(feature = "std"))]
+extern crate alloc;
+
+pub use crate::any::CloneAny;
+
+mod any;
+
+#[cfg(any(feature = "std", feature = "hashbrown"))]
+macro_rules! everything {
+ ($example_init:literal, $($parent:ident)::+ $(, $entry_generics:ty)?) => {
+ use core::any::{Any, TypeId};
+ use core::hash::BuildHasherDefault;
+ use core::marker::PhantomData;
+
+ #[cfg(not(feature = "std"))]
+ use alloc::boxed::Box;
+
+ use ::$($parent)::+::hash_map::{self, HashMap};
+
+ use crate::any::{Downcast, IntoBox};
+
+ /// Raw access to the underlying `HashMap`.
+ ///
+ /// This alias is provided for convenience because of the ugly third generic parameter.
+ pub type RawMap<A> = HashMap<TypeId, Box<A>, BuildHasherDefault<TypeIdHasher>>;
+
+ /// A collection containing zero or one values for any given type and allowing convenient,
+ /// type-safe access to those values.
+ ///
+ /// The type parameter `A` allows you to use a different value type; normally you will want
+ /// it to be `core::any::Any` (also known as `std::any::Any`), but there are other choices:
+ ///
+ /// - If you want the entire map to be cloneable, use `CloneAny` instead of `Any`; with
+ /// that, you can only add types that implement `Clone` to the map.
+ /// - You can add on `+ Send` or `+ Send + Sync` (e.g. `Map<dyn Any + Send>`) to add those
+ /// auto traits.
+ ///
+ /// Cumulatively, there are thus six forms of map:
+ ///
+ /// - <code>[Map]<dyn [core::any::Any]></code>,
+ /// also spelled [`AnyMap`] for convenience.
+ /// - <code>[Map]<dyn [core::any::Any] + Send></code>
+ /// - <code>[Map]<dyn [core::any::Any] + Send + Sync></code>
+ /// - <code>[Map]<dyn [CloneAny]></code>
+ /// - <code>[Map]<dyn [CloneAny] + Send></code>
+ /// - <code>[Map]<dyn [CloneAny] + Send + Sync></code>
+ ///
+ /// ## Example
+ ///
+ /// (Here using the [`AnyMap`] convenience alias; the first line could use
+ /// <code>[anymap::Map][Map]::<[core::any::Any]>::new()</code> instead if desired.)
+ ///
+ /// ```rust
+ #[doc = $example_init]
+ /// assert_eq!(data.get(), None::<&i32>);
+ /// data.insert(42i32);
+ /// assert_eq!(data.get(), Some(&42i32));
+ /// data.remove::<i32>();
+ /// assert_eq!(data.get::<i32>(), None);
+ ///
+ /// #[derive(Clone, PartialEq, Debug)]
+ /// struct Foo {
+ /// str: String,
+ /// }
+ ///
+ /// assert_eq!(data.get::<Foo>(), None);
+ /// data.insert(Foo { str: format!("foo") });
+ /// assert_eq!(data.get(), Some(&Foo { str: format!("foo") }));
+ /// data.get_mut::<Foo>().map(|foo| foo.str.push('t'));
+ /// assert_eq!(&*data.get::<Foo>().unwrap().str, "foot");
+ /// ```
+ ///
+ /// Values containing non-static references are not permitted.
+ #[derive(Debug)]
+ pub struct Map<A: ?Sized + Downcast = dyn Any> {
+ raw: RawMap<A>,
+ }