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

Support Duration with no_std for Rust >= 1.25 #649

Merged
merged 1 commit into from Nov 22, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.rs
Expand Up @@ -2,6 +2,9 @@ extern crate rustc_version;
use rustc_version::{version, Version};

fn main() {
if version().unwrap() >= Version::parse("1.25.0").unwrap() {
println!("cargo:rustc-cfg=rust_1_25");
}
if version().unwrap() >= Version::parse("1.26.0").unwrap() {
println!("cargo:rustc-cfg=rust_1_26");
}
Expand Down
15 changes: 10 additions & 5 deletions src/distributions/uniform.rs
Expand Up @@ -111,6 +111,8 @@

#[cfg(feature = "std")]
use std::time::Duration;
#[cfg(all(not(feature = "std"), rust_1_25))]
use core::time::Duration;

use Rng;
use distributions::Distribution;
Expand Down Expand Up @@ -833,14 +835,14 @@ uniform_float_impl! { f64x8, u64x8, f64, u64, 64 - 52 }
///
/// [`UniformSampler`]: trait.UniformSampler.html
/// [`Uniform`]: struct.Uniform.html
#[cfg(feature = "std")]
#[cfg(any(feature = "std", rust_1_25))]
#[derive(Clone, Copy, Debug)]
pub struct UniformDuration {
mode: UniformDurationMode,
offset: u32,
}

#[cfg(feature = "std")]
#[cfg(any(feature = "std", rust_1_25))]
#[derive(Debug, Copy, Clone)]
enum UniformDurationMode {
Small {
Expand All @@ -857,12 +859,12 @@ enum UniformDurationMode {
}
}

#[cfg(feature = "std")]
#[cfg(any(feature = "std", rust_1_25))]
impl SampleUniform for Duration {
type Sampler = UniformDuration;
}

#[cfg(feature = "std")]
#[cfg(any(feature = "std", rust_1_25))]
impl UniformSampler for UniformDuration {
type X = Duration;

Expand Down Expand Up @@ -1206,9 +1208,12 @@ mod tests {


#[test]
#[cfg(feature = "std")]
#[cfg(any(feature = "std", rust_1_25))]
fn test_durations() {
#[cfg(feature = "std")]
use std::time::Duration;
#[cfg(all(not(feature = "std"), rust_1_25))]
use core::time::Duration;

let mut rng = ::test::rng(253);

Expand Down