Skip to content

Commit 76bf777

Browse files
author
Jethro Beekman
committed
Add more features to support stable
1 parent 2c97416 commit 76bf777

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ keywords = ["random", "rng"]
1515

1616
[dependencies]
1717
libc = { version = "0.2", optional = true }
18-
core_io = { version = "0.0", optional = true }
18+
core_io = { version = "0.0", optional = true } # enable use of read module on no_std
1919

2020
[features]
2121
default = ["libc"]
22-
no_std = ["core_io"]
22+
no_std = []
23+
box = [] # enable use of Box on no_std, requires alloc crate and feature
24+
vec = [] # enable use of Vec on no_std, requires collections crate and feature
2325

2426
[dev-dependencies]
2527
log = "0.3.0"

src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,23 +242,24 @@
242242
html_root_url = "https://doc.rust-lang.org/rand/")]
243243

244244
#![cfg_attr(feature="no_std",no_std)]
245-
#![cfg_attr(feature="no_std",feature(alloc,collections))]
245+
#![cfg_attr(feature="box",feature(alloc))]
246+
#![cfg_attr(feature="vec",feature(collections))]
246247

247248
#[cfg(test)] #[macro_use] extern crate log;
248249

249250
#[cfg(not(feature="no_std"))] extern crate std as core;
250-
#[cfg(feature="no_std")] extern crate core_io as io;
251-
#[cfg(feature="no_std")] extern crate alloc;
252-
#[cfg(feature="no_std")] extern crate collections;
251+
#[cfg(feature="core_io")] extern crate core_io as io;
252+
#[cfg(feature="box")] extern crate alloc;
253+
#[cfg(feature="vec")] extern crate collections;
253254

254255
#[cfg(not(feature="no_std"))] use core::cell::RefCell;
255256
use core::marker;
256257
use core::mem;
257258
#[cfg(not(feature="no_std"))] use std::io;
258259
#[cfg(not(feature="no_std"))] use std::rc::Rc;
259260
use core::num::Wrapping as w;
260-
#[cfg(feature="no_std")] use alloc::boxed::Box;
261-
#[cfg(feature="no_std")] use collections::vec::Vec;
261+
#[cfg(feature="box")] use alloc::boxed::Box;
262+
#[cfg(feature="vec")] use collections::vec::Vec;
262263

263264
#[cfg(not(feature="no_std"))] pub use os::OsRng;
264265

@@ -279,7 +280,7 @@ pub mod chacha;
279280
pub mod reseeding;
280281
mod rand_impls;
281282
#[cfg(not(feature="no_std"))] pub mod os;
282-
pub mod read;
283+
#[cfg(any(not(feature="no_std"),feature="core_io"))] pub mod read;
283284

284285
#[allow(bad_style)]
285286
type w64 = w<u64>;
@@ -586,6 +587,7 @@ impl<'a, R: ?Sized> Rng for &'a mut R where R: Rng {
586587
}
587588
}
588589

590+
#[cfg(any(feature="box",not(feature="no_std")))]
589591
impl<R: ?Sized> Rng for Box<R> where R: Rng {
590592
fn next_u32(&mut self) -> u32 {
591593
(**self).next_u32()
@@ -989,6 +991,7 @@ pub fn random<T: Rand>() -> T {
989991
/// let sample = sample(&mut rng, 1..100, 5);
990992
/// println!("{:?}", sample);
991993
/// ```
994+
#[cfg(any(feature="vec",not(feature="no_std")))]
992995
pub fn sample<T, I, R>(rng: &mut R, iterable: I, amount: usize) -> Vec<T>
993996
where I: IntoIterator<Item=T>,
994997
R: Rng,

0 commit comments

Comments
 (0)