Merge pull request #137 from jacwah/derive-debug
Derive Debug for distibutions
diff --git a/.travis.yml b/.travis.yml
index 2c5dbd6..73058dc 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,8 +9,10 @@
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
script:
- cargo build --verbose
+ - ([ $TRAVIS_RUST_VERSION != nightly ] || cargo build --verbose --features nightly)
- cargo test --verbose
- - cargo doc --no-deps
+ - ([ $TRAVIS_RUST_VERSION != nightly ] || cargo test --verbose --features nightly)
+ - ([ $TRAVIS_RUST_VERSION != nightly ] || cargo doc --no-deps --features nightly)
after_success:
- travis-cargo --only nightly doc-upload
env:
diff --git a/Cargo.toml b/Cargo.toml
index 755b6f1..393ec45 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,6 +14,10 @@
keywords = ["random", "rng"]
categories = ["algorithms"]
+[features]
+i128_support = []
+nightly = ["i128_support"]
+
[dependencies]
libc = "0.2"
diff --git a/appveyor.yml b/appveyor.yml
index 4a61042..9085347 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -15,3 +15,4 @@
test_script:
- cargo test --verbose --target %TARGET%
+ - cargo test --verbose --target %TARGET% --features nightly
diff --git a/src/lib.rs b/src/lib.rs
index 955a3c8..fd0fbf0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -243,6 +243,8 @@
#![deny(missing_debug_implementations)]
+#![cfg_attr(feature = "i128_support", feature(i128_type))]
+
#[cfg(test)] #[macro_use] extern crate log;
@@ -292,7 +294,7 @@
///
/// This rarely needs to be called directly, prefer `r.gen()` to
/// `r.next_u32()`.
- // FIXME #7771: Should be implemented in terms of next_u64
+ // FIXME #rust-lang/rfcs#628: Should be implemented in terms of next_u64
fn next_u32(&mut self) -> u32;
/// Return the next random u64.
diff --git a/src/rand_impls.rs b/src/rand_impls.rs
index 5a7e3de..a9cf5d9 100644
--- a/src/rand_impls.rs
+++ b/src/rand_impls.rs
@@ -54,6 +54,14 @@
}
}
+#[cfg(feature = "i128_support")]
+impl Rand for i128 {
+ #[inline]
+ fn rand<R: Rng>(rng: &mut R) -> i128 {
+ rng.gen::<u128>() as i128
+ }
+}
+
impl Rand for usize {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> usize {
@@ -93,6 +101,15 @@
}
}
+#[cfg(feature = "i128_support")]
+impl Rand for u128 {
+ #[inline]
+ fn rand<R: Rng>(rng: &mut R) -> u128 {
+ ((rng.next_u64() as u128) << 64) | (rng.next_u64() as u128)
+ }
+}
+
+
macro_rules! float_impls {
($mod_name:ident, $ty:ty, $mantissa_bits:expr, $method_name:ident) => {
mod $mod_name {