diff --git a/Cargo.toml b/Cargo.toml index a0548389..ed0228e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ bench = false [dependencies] serde = { version = "1.0", optional = true } +hashmap_core = { version = "0.1.10", optional = true } [dev-dependencies] itertools = "0.7.0" # 0.8 not compiles on Rust 1.18 @@ -39,6 +40,10 @@ lazy_static = "1" serde_test = "1.0.5" [features] +default = ["std"] +std = [] +core = ["hashmap_core"] + # Serialization with serde 1.0 serde-1 = ["serde"] diff --git a/src/lib.rs b/src/lib.rs index 1a0655e3..ceffe122 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,34 @@ //! upgrade policy, where in a later 1.x version, we will raise the minimum //! required Rust version. +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(not(feature = "std"))] +#[macro_use] +extern crate alloc; + +#[cfg(not(feature = "std"))] +extern crate hashmap_core; + +#[cfg(not(feature = "std"))] +mod std { + pub use core::*; + + pub mod vec { + pub use alloc::vec::*; + } + + pub mod boxed { + pub use alloc::boxed::*; + } + + pub mod collections { + pub mod hash_map { + pub use hashmap_core::map::*; + } + } +} + #[macro_use] mod macros; #[cfg(feature = "serde-1")] diff --git a/src/map.rs b/src/map.rs index a52d3d88..956f6c2e 100644 --- a/src/map.rs +++ b/src/map.rs @@ -9,6 +9,8 @@ use std::hash::Hasher; use std::iter::FromIterator; use std::collections::hash_map::RandomState; use std::ops::RangeFull; +use std::boxed::Box; +use std::vec::Vec; use std::cmp::{max, Ordering}; use std::fmt;