1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
//! A shim crate for to import items of alloc crate ergonomically. //! //! [Examples](https://github.com/taiki-e/alloc-shim/tree/master/examples) //! //! ## Usage //! //! Add this to your `Cargo.toml`: //! //! ```toml //! [dependencies] //! alloc-shim = { version = "0.2.1" } //! ``` //! //! Set the features so that `std` depends on `alloc-shim/std`, and `alloc` depends on `alloc-shim/alloc`: //! //! ```toml //! [features] //! std = ["alloc-shim/std"] //! alloc = ["alloc-shim/alloc"] //! ``` //! //! Now, you can use alloc-shim: //! //! ```rust //! #[cfg(any(feature = "alloc", feature = "std"))] //! use alloc::prelude::v1::*; // And more... //! ``` //! //! The current version of alloc-shim requires Rust 1.31 or later. //! #![doc(html_root_url = "https://docs.rs/alloc-shim/0.2.1")] #![cfg_attr(feature = "alloc", feature(alloc, futures_api))] #[cfg(all(feature = "alloc", not(feature = "std")))] extern crate alloc as liballoc; #[cfg(not(feature = "std"))] mod shim { // str: https://doc.rust-lang.org/nightly/core/str/index.html vs https://doc.rust-lang.org/nightly/alloc/str/index.html pub use core::{str, *}; #[cfg(feature = "alloc")] pub use liballoc::{alloc, borrow, fmt, slice, task, *}; // The layout in the prelude module is different for `std` and `alloc`. /// The alloc Prelude #[cfg(feature = "alloc")] pub mod prelude { /// The alloc Prelude pub mod v1 { pub use core::prelude::v1::*; pub use liballoc::prelude::*; } } // `alloc::sync` does not include `atomic` module /// Synchronization primitives #[cfg(feature = "alloc")] pub mod sync { pub use core::sync::atomic; pub use liballoc::sync::*; } } #[cfg(not(feature = "std"))] pub use self::shim::*; #[cfg(feature = "std")] pub use std::*;