David LeGare | 77e4bb9 | 2022-03-02 16:21:23 +0000 | [diff] [blame] | 1 | //! `no_std` compatibility |
| 2 | |
| 3 | // If we depend on `ahash`, use its hasher. |
| 4 | #[cfg(feature = "ahash")] |
| 5 | pub use ahash::RandomState; |
| 6 | |
| 7 | // Use the `std` hasher if we don’t depend on `ahash` but do depend on |
| 8 | // `std`. |
| 9 | #[cfg(all(not(feature = "ahash"), feature = "std"))] |
| 10 | pub use std::collections::hash_map::RandomState; |
| 11 | |
| 12 | // If we depend on neither `ahash` nor `std` then it’s an error. |
| 13 | #[cfg(not(any(feature = "ahash", feature = "std")))] |
| 14 | compile_error!("weak-table: no_std requires that you enable the `ahash` feature."); |
| 15 | |
| 16 | // If we depend on `std`, alias `lib` to `std`. |
| 17 | #[cfg(feature = "std")] |
| 18 | mod lib { |
| 19 | extern crate std; |
| 20 | pub use std::*; |
| 21 | } |
| 22 | |
| 23 | // Otherwise, we are `no_std`, so alias `lib` to `alloc`. |
| 24 | #[cfg(not(feature = "std"))] |
| 25 | mod lib { |
| 26 | extern crate alloc; |
| 27 | pub use alloc::*; |
| 28 | } |
| 29 | |
| 30 | // Stuff from `std`/`alloc` that we use often. |
| 31 | pub use lib::{ |
| 32 | boxed::Box, |
| 33 | rc, |
| 34 | slice, |
| 35 | string::String, |
| 36 | sync, |
| 37 | vec::{self, Vec}, |
| 38 | }; |
| 39 | |
| 40 | // Stuff from `core` that we use often: |
| 41 | pub use core::{ |
| 42 | borrow::Borrow, |
| 43 | cmp::max, |
| 44 | hash::{BuildHasher, Hash, Hasher}, |
| 45 | iter::{self, FromIterator}, |
| 46 | fmt::{self, Debug, Formatter}, |
| 47 | mem, |
| 48 | ops::{self, Deref, Index, IndexMut}, |
| 49 | }; |
| 50 | |
| 51 | // When testing, we need the `eprintln` macro from `std`: |
| 52 | #[cfg(test)] |
| 53 | extern crate std; |
| 54 | |
| 55 | #[cfg(test)] |
| 56 | pub use std::eprintln; |