|
5 | 5 | //! Small vectors in various sizes. These store a certain number of elements inline, and fall back
|
6 | 6 | //! to the heap for larger allocations. This can be a useful optimization for improving cache
|
7 | 7 | //! locality and reducing allocator traffic for workloads that fit within the inline buffer.
|
| 8 | +//! |
| 9 | +//! ## no_std support |
| 10 | +//! |
| 11 | +//! By default, `smallvec` depends on `libstd`. However, it can be configured to use the unstable |
| 12 | +//! `liballoc` API instead, for use on platforms that have `liballoc` but not `libstd`. This |
| 13 | +//! configuration is currently unstable and is not guaranteed to work on all versions of Rust. |
| 14 | +//! |
| 15 | +//! To depend on `smallvec` without `libstd`, use `default-features = false` in the `smallvec` |
| 16 | +//! section of Cargo.toml to disable its `"std"` feature. |
8 | 17 |
|
9 | 18 | #![cfg_attr(not(feature = "std"), no_std)]
|
10 |
| -#![cfg_attr(not(feature = "std"), feature(collections))] |
| 19 | +#![cfg_attr(not(feature = "std"), feature(alloc))] |
11 | 20 |
|
12 | 21 |
|
13 | 22 | #[cfg(not(feature = "std"))]
|
14 |
| -extern crate collections; |
| 23 | +#[cfg_attr(test, macro_use)] |
| 24 | +extern crate alloc; |
15 | 25 |
|
16 | 26 | #[cfg(not(feature = "std"))]
|
17 |
| -use collections::Vec; |
| 27 | +use alloc::Vec; |
18 | 28 |
|
19 | 29 | #[cfg(feature="heapsizeof")]
|
20 | 30 | extern crate heapsize;
|
@@ -967,9 +977,18 @@ impl_array!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32, 3
|
967 | 977 | #[cfg(test)]
|
968 | 978 | pub mod tests {
|
969 | 979 | use SmallVec;
|
970 |
| - use std::borrow::ToOwned; |
| 980 | + |
971 | 981 | use std::iter::FromIterator;
|
972 | 982 |
|
| 983 | + #[cfg(feature = "std")] |
| 984 | + use std::borrow::ToOwned; |
| 985 | + #[cfg(not(feature = "std"))] |
| 986 | + use alloc::borrow::ToOwned; |
| 987 | + #[cfg(not(feature = "std"))] |
| 988 | + use alloc::boxed::Box; |
| 989 | + #[cfg(not(feature = "std"))] |
| 990 | + use alloc::vec::Vec; |
| 991 | + |
973 | 992 | #[cfg(feature="heapsizeof")]
|
974 | 993 | use heapsize::HeapSizeOf;
|
975 | 994 | #[cfg(feature="heapsizeof")]
|
@@ -1311,6 +1330,7 @@ pub mod tests {
|
1311 | 1330 | assert!(c > b);
|
1312 | 1331 | }
|
1313 | 1332 |
|
| 1333 | + #[cfg(feature = "std")] |
1314 | 1334 | #[test]
|
1315 | 1335 | fn test_hash() {
|
1316 | 1336 | use std::hash::Hash;
|
|
0 commit comments