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

Add feature-flag based support option for no_std + alloc #49

Merged
merged 2 commits into from
Apr 23, 2018
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
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bit-vec"
version = "0.4.4"
version = "0.5.0"
authors = ["Alexis Beingessner <a.beingessner@gmail.com>"]
license = "MIT/Apache-2.0"
description = "A vector of bits"
Expand All @@ -14,4 +14,8 @@ readme = "README.md"
rand = "0.3.15"

[features]
default = ["std"]

nightly = []

std = []
36 changes: 26 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,38 @@
//! assert_eq!(num_primes, 1_229);
//! ```

#![no_std]
#![cfg_attr(not(feature="std"), feature(alloc))]

#![cfg_attr(all(test, feature = "nightly"), feature(test))]
#[cfg(all(test, feature = "nightly"))] extern crate test;
#[cfg(all(test, feature = "nightly"))] extern crate rand;

use std::cmp::Ordering;
use std::cmp;
use std::fmt;
use std::hash;
use std::iter::{Chain, Enumerate, Repeat, Skip, Take, repeat};
use std::iter::FromIterator;
use std::slice;
use std::{u8, usize};
#[cfg(any(test, feature = "std"))]
#[macro_use]
extern crate std;
#[cfg(feature="std")]
use std::vec::Vec;

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

use core::cmp::Ordering;
use core::cmp;
use core::fmt;
use core::hash;
use core::iter::{Chain, Enumerate, Repeat, Skip, Take, repeat};
use core::iter::FromIterator;
use core::slice;
use core::{u8, usize};

type MutBlocks<'a, B> = slice::IterMut<'a, B>;
type MatchWords<'a, B> = Chain<Enumerate<Blocks<'a, B>>, Skip<Take<Enumerate<Repeat<B>>>>>;

use std::ops::*;
use core::ops::*;

/// Abstracts over a pile of bits (basically unsigned primitives)
pub trait BitBlock:
Expand Down Expand Up @@ -154,7 +169,7 @@ bit_block_impl!{
(u16, 16),
(u32, 32),
(u64, 64),
(usize, std::mem::size_of::<usize>() * 8)
(usize, core::mem::size_of::<usize>() * 8)
}


Expand Down Expand Up @@ -1318,6 +1333,7 @@ impl<'a, B: BitBlock> ExactSizeIterator for Blocks<'a, B> {}
#[cfg(test)]
mod tests {
use super::{BitVec, Iter};
use std::vec::Vec;

// This is stupid, but I want to differentiate from a "random" 32
const U32_BITS: usize = 32;
Expand Down