Skip to content

Commit 7bda532

Browse files
author
bors-servo
authored
Auto merge of #53 - mbrubeck:no_std, r=emilio
Document and test no_std support This builds on the new "std" Cargo feature added in #49. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/53) <!-- Reviewable:end -->
2 parents 2549c2a + bf9ac18 commit 7bda532

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ script: |
88
cargo build --features=heapsizeof --verbose &&
99
cargo test --verbose &&
1010
cargo test --features=heapsizeof --verbose &&
11+
([ $TRAVIS_RUST_VERSION != nightly ] || cargo test --verbose --no-default-features) &&
1112
([ $TRAVIS_RUST_VERSION != nightly ] || cargo bench --verbose bench)
1213
notifications:
1314
webhooks: http://build.servo.org:54856/travis

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
[package]
22
name = "smallvec"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
authors = ["Simon Sapin <[email protected]>"]
55
license = "MPL-2.0"
66
repository = "https://github.com/servo/rust-smallvec"
77
description = "'Small vector' optimization: store up to a small number of items on the stack"
8-
keywords = ["small", "vec", "vector", "stack"]
8+
keywords = ["small", "vec", "vector", "stack", "no_std"]
99
readme = "README.md"
1010
documentation = "http://doc.servo.org/smallvec/"
1111

1212
[features]
1313
heapsizeof = ["heapsize", "std"]
14-
collections = []
1514
std = []
1615
default = ["std"]
1716

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
rust-smallvec
22
=============
33

4-
[Documentation](http://doc.servo.org/smallvec/)
4+
[Documentation](http://docs.rs/smallvec/)
55

66
"Small vector" optimization for Rust: store up to a small number of items on the stack

lib.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,26 @@
55
//! Small vectors in various sizes. These store a certain number of elements inline, and fall back
66
//! to the heap for larger allocations. This can be a useful optimization for improving cache
77
//! 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.
817
918
#![cfg_attr(not(feature = "std"), no_std)]
10-
#![cfg_attr(not(feature = "std"), feature(collections))]
19+
#![cfg_attr(not(feature = "std"), feature(alloc))]
1120

1221

1322
#[cfg(not(feature = "std"))]
14-
extern crate collections;
23+
#[cfg_attr(test, macro_use)]
24+
extern crate alloc;
1525

1626
#[cfg(not(feature = "std"))]
17-
use collections::Vec;
27+
use alloc::Vec;
1828

1929
#[cfg(feature="heapsizeof")]
2030
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
967977
#[cfg(test)]
968978
pub mod tests {
969979
use SmallVec;
970-
use std::borrow::ToOwned;
980+
971981
use std::iter::FromIterator;
972982

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+
973992
#[cfg(feature="heapsizeof")]
974993
use heapsize::HeapSizeOf;
975994
#[cfg(feature="heapsizeof")]
@@ -1311,6 +1330,7 @@ pub mod tests {
13111330
assert!(c > b);
13121331
}
13131332

1333+
#[cfg(feature = "std")]
13141334
#[test]
13151335
fn test_hash() {
13161336
use std::hash::Hash;

0 commit comments

Comments
 (0)