Skip to content

Commit 5511699

Browse files
authored
Merge pull request #649 from vks/no_std-duration
Support Duration with no_std for Rust >= 1.25
2 parents 3eadab7 + 9ae55fc commit 5511699

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ extern crate rustc_version;
22
use rustc_version::{version, Version};
33

44
fn main() {
5+
if version().unwrap() >= Version::parse("1.25.0").unwrap() {
6+
println!("cargo:rustc-cfg=rust_1_25");
7+
}
58
if version().unwrap() >= Version::parse("1.26.0").unwrap() {
69
println!("cargo:rustc-cfg=rust_1_26");
710
}

src/distributions/uniform.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@
111111
112112
#[cfg(feature = "std")]
113113
use std::time::Duration;
114+
#[cfg(all(not(feature = "std"), rust_1_25))]
115+
use core::time::Duration;
114116

115117
use Rng;
116118
use distributions::Distribution;
@@ -833,14 +835,14 @@ uniform_float_impl! { f64x8, u64x8, f64, u64, 64 - 52 }
833835
///
834836
/// [`UniformSampler`]: trait.UniformSampler.html
835837
/// [`Uniform`]: struct.Uniform.html
836-
#[cfg(feature = "std")]
838+
#[cfg(any(feature = "std", rust_1_25))]
837839
#[derive(Clone, Copy, Debug)]
838840
pub struct UniformDuration {
839841
mode: UniformDurationMode,
840842
offset: u32,
841843
}
842844

843-
#[cfg(feature = "std")]
845+
#[cfg(any(feature = "std", rust_1_25))]
844846
#[derive(Debug, Copy, Clone)]
845847
enum UniformDurationMode {
846848
Small {
@@ -857,12 +859,12 @@ enum UniformDurationMode {
857859
}
858860
}
859861

860-
#[cfg(feature = "std")]
862+
#[cfg(any(feature = "std", rust_1_25))]
861863
impl SampleUniform for Duration {
862864
type Sampler = UniformDuration;
863865
}
864866

865-
#[cfg(feature = "std")]
867+
#[cfg(any(feature = "std", rust_1_25))]
866868
impl UniformSampler for UniformDuration {
867869
type X = Duration;
868870

@@ -1206,9 +1208,12 @@ mod tests {
12061208

12071209

12081210
#[test]
1209-
#[cfg(feature = "std")]
1211+
#[cfg(any(feature = "std", rust_1_25))]
12101212
fn test_durations() {
1213+
#[cfg(feature = "std")]
12111214
use std::time::Duration;
1215+
#[cfg(all(not(feature = "std"), rust_1_25))]
1216+
use core::time::Duration;
12121217

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

0 commit comments

Comments
 (0)