X-Git-Url: https://git.chrismorgan.info/anymap/blobdiff_plain/8bc7c76088639ab3a65a642f5d79ce20ef20e2f4..0a1c85f8655a71b995d228ed0c9496f732268c5b:/src/lib.rs diff --git a/src/lib.rs b/src/lib.rs index 1ad840b..6366c70 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,8 +4,19 @@ #![warn(missing_docs, unused_results)] -use std::any::{Any, TypeId}; -use std::marker::PhantomData; +#![cfg_attr(not(feature = "std"), no_std)] + +use core::any::{Any, TypeId}; +use core::marker::PhantomData; + +#[cfg(not(any(feature = "std", feature = "hashbrown")))] +compile_error!("anymap: you must enable the 'std' feature or the 'hashbrown' feature"); + +#[cfg(not(feature = "std"))] +extern crate alloc; + +#[cfg(not(feature = "std"))] +use alloc::boxed::Box; use raw::RawMap; use any::{UncheckedAnyExt, IntoBox}; @@ -95,7 +106,7 @@ pub mod raw; /// 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 `std::any::Any`, but there are other choices: +/// 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. @@ -104,9 +115,9 @@ pub mod raw; /// /// Cumulatively, there are thus six forms of map: /// -/// - [Map]<dyn [std::any::Any]>, also spelled [`AnyMap`] for convenience. -/// - [Map]<dyn [std::any::Any] + Send> -/// - [Map]<dyn [std::any::Any] + Send + Sync> +/// - [Map]<dyn [core::any::Any]>, also spelled [`AnyMap`] for convenience. +/// - [Map]<dyn [core::any::Any] + Send> +/// - [Map]<dyn [core::any::Any] + Send + Sync> /// - [Map]<dyn [CloneAny]> /// - [Map]<dyn [CloneAny] + Send> /// - [Map]<dyn [CloneAny] + Send + Sync> @@ -114,7 +125,7 @@ pub mod raw; /// ## Example /// /// (Here using the [`AnyMap`] convenience alias; the first line could use -/// [anymap::Map][Map]::<[std::any::Any]>::new() instead if desired.) +/// [anymap::Map][Map]::<[core::any::Any]>::new() instead if desired.) /// /// ```rust /// let mut data = anymap::AnyMap::new(); @@ -444,7 +455,7 @@ mod tests { fn assert_send() { } fn assert_sync() { } fn assert_clone() { } - fn assert_debug() { } + fn assert_debug() { } assert_send::>(); assert_send::>(); assert_sync::>();