no_std support
[anymap] / src / lib.rs
index 31b271e83ce89110d8216527de55b2c7807c6ea4..6366c70b5a3781fda251734893cf2585d7f196bc 100644 (file)
@@ -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:
 ///
-/// - <code>[Map]&lt;dyn [std::any::Any]&gt;</code>, also spelled [`AnyMap`] for convenience.
-/// - <code>[Map]&lt;dyn [std::any::Any] + Send&gt;</code>
-/// - <code>[Map]&lt;dyn [std::any::Any] + Send + Sync&gt;</code>
+/// - <code>[Map]&lt;dyn [core::any::Any]&gt;</code>, also spelled [`AnyMap`] for convenience.
+/// - <code>[Map]&lt;dyn [core::any::Any] + Send&gt;</code>
+/// - <code>[Map]&lt;dyn [core::any::Any] + Send + Sync&gt;</code>
 /// - <code>[Map]&lt;dyn [CloneAny]&gt;</code>
 /// - <code>[Map]&lt;dyn [CloneAny] + Send&gt;</code>
 /// - <code>[Map]&lt;dyn [CloneAny] + Send + Sync&gt;</code>
@@ -114,7 +125,7 @@ pub mod raw;
 /// ## Example
 ///
 /// (Here using the [`AnyMap`] convenience alias; the first line could use
-/// <code>[anymap::Map][Map]::&lt;[std::any::Any]&gt;::new()</code> instead if desired.)
+/// <code>[anymap::Map][Map]::&lt;[core::any::Any]&gt;::new()</code> instead if desired.)
 ///
 /// ```rust
 /// let mut data = anymap::AnyMap::new();
@@ -236,10 +247,10 @@ impl<A: ?Sized + UncheckedAnyExt> AsMut<RawMap<A>> for Map<A> {
     }
 }
 
-impl<A: ?Sized + UncheckedAnyExt> Into<RawMap<A>> for Map<A> {
+impl<A: ?Sized + UncheckedAnyExt> From<Map<A>> for RawMap<A> {
     #[inline]
-    fn into(self) -> RawMap<A> {
-        self.raw
+    fn from(map: Map<A>) -> RawMap<A> {
+        map.raw
     }
 }
 
@@ -444,7 +455,7 @@ mod tests {
         fn assert_send<T: Send>() { }
         fn assert_sync<T: Sync>() { }
         fn assert_clone<T: Clone>() { }
-        fn assert_debug<T: ::std::fmt::Debug>() { }
+        fn assert_debug<T: ::core::fmt::Debug>() { }
         assert_send::<Map<dyn Any + Send>>();
         assert_send::<Map<dyn Any + Send + Sync>>();
         assert_sync::<Map<dyn Any + Send + Sync>>();