Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document and test no_std support #53

Merged
merged 5 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = []
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused.

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