Skip to content

Commit

Permalink
Auto merge of #53 - mbrubeck:no_std, r=emilio
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
bors-servo authored Jun 29, 2017
2 parents 2549c2a + bf9ac18 commit 7bda532
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ script: |
cargo build --features=heapsizeof --verbose &&
cargo test --verbose &&
cargo test --features=heapsizeof --verbose &&
([ $TRAVIS_RUST_VERSION != nightly ] || cargo test --verbose --no-default-features) &&
([ $TRAVIS_RUST_VERSION != nightly ] || cargo bench --verbose bench)
notifications:
webhooks: http://build.servo.org:54856/travis
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
[package]
name = "smallvec"
version = "0.4.0"
version = "0.4.1"
authors = ["Simon Sapin <[email protected]>"]
license = "MPL-2.0"
repository = "https://github.com/servo/rust-smallvec"
description = "'Small vector' optimization: store up to a small number of items on the stack"
keywords = ["small", "vec", "vector", "stack"]
keywords = ["small", "vec", "vector", "stack", "no_std"]
readme = "README.md"
documentation = "http://doc.servo.org/smallvec/"

[features]
heapsizeof = ["heapsize", "std"]
collections = []
std = []
default = ["std"]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
rust-smallvec
=============

[Documentation](http://doc.servo.org/smallvec/)
[Documentation](http://docs.rs/smallvec/)

"Small vector" optimization for Rust: store up to a small number of items on the stack
28 changes: 24 additions & 4 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@
//! Small vectors in various sizes. These store a certain number of elements inline, and fall back
//! to the heap for larger allocations. This can be a useful optimization for improving cache
//! locality and reducing allocator traffic for workloads that fit within the inline buffer.
//!
//! ## no_std support
//!
//! By default, `smallvec` depends on `libstd`. However, it can be configured to use the unstable
//! `liballoc` API instead, for use on platforms that have `liballoc` but not `libstd`. This
//! configuration is currently unstable and is not guaranteed to work on all versions of Rust.
//!
//! To depend on `smallvec` without `libstd`, use `default-features = false` in the `smallvec`
//! section of Cargo.toml to disable its `"std"` feature.
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(collections))]
#![cfg_attr(not(feature = "std"), feature(alloc))]


#[cfg(not(feature = "std"))]
extern crate collections;
#[cfg_attr(test, macro_use)]
extern crate alloc;

#[cfg(not(feature = "std"))]
use collections::Vec;
use alloc::Vec;

#[cfg(feature="heapsizeof")]
extern crate heapsize;
Expand Down Expand Up @@ -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
#[cfg(test)]
pub mod tests {
use SmallVec;
use std::borrow::ToOwned;

use std::iter::FromIterator;

#[cfg(feature = "std")]
use std::borrow::ToOwned;
#[cfg(not(feature = "std"))]
use alloc::borrow::ToOwned;
#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

#[cfg(feature="heapsizeof")]
use heapsize::HeapSizeOf;
#[cfg(feature="heapsizeof")]
Expand Down Expand Up @@ -1311,6 +1330,7 @@ pub mod tests {
assert!(c > b);
}

#[cfg(feature = "std")]
#[test]
fn test_hash() {
use std::hash::Hash;
Expand Down

0 comments on commit 7bda532

Please sign in to comment.