59
59
//! use rand::distributions::uniform::{Uniform, SampleUniform};
60
60
//! use rand::distributions::uniform::{UniformSampler, UniformFloat};
61
61
//!
62
- //! #[derive(Clone, Copy, PartialEq, PartialOrd)]
63
62
//! struct MyF32(f32);
64
63
//!
65
64
//! #[derive(Clone, Copy, Debug)]
66
65
//! struct UniformMyF32 {
67
66
//! inner: UniformFloat<f32>,
68
67
//! }
68
+ //!
69
69
//! impl UniformSampler for UniformMyF32 {
70
70
//! type X = MyF32;
71
71
//! fn new(low: Self::X, high: Self::X) -> Self {
@@ -251,6 +251,17 @@ pub trait UniformSampler: Sized {
251
251
}
252
252
}
253
253
254
+ impl < X : SampleUniform > From < :: core:: ops:: Range < X > > for Uniform < X > {
255
+ fn from ( r : :: core:: ops:: Range < X > ) -> Uniform < X > {
256
+ Uniform :: new ( r. start , r. end )
257
+ }
258
+ }
259
+
260
+ ////////////////////////////////////////////////////////////////////////////////
261
+
262
+ // What follows are all back-ends.
263
+
264
+
254
265
/// The back-end implementing [`UniformSampler`] for integer types.
255
266
///
256
267
/// Unless you are implementing [`UniformSampler`] for your own type, this type
@@ -406,12 +417,6 @@ macro_rules! uniform_int_impl {
406
417
}
407
418
}
408
419
409
- impl < X : SampleUniform > From < :: core:: ops:: Range < X > > for Uniform < X > {
410
- fn from ( r : :: core:: ops:: Range < X > ) -> Uniform < X > {
411
- Uniform :: new ( r. start , r. end )
412
- }
413
- }
414
-
415
420
uniform_int_impl ! { i8 , i8 , u8 , i32 , u32 }
416
421
uniform_int_impl ! { i16 , i16 , u16 , i32 , u32 }
417
422
uniform_int_impl ! { i32 , i32 , u32 , i32 , u32 }
@@ -447,7 +452,6 @@ macro_rules! wmul_impl {
447
452
}
448
453
}
449
454
}
450
-
451
455
wmul_impl ! { u8 , u16 , 8 }
452
456
wmul_impl ! { u16 , u32 , 16 }
453
457
wmul_impl ! { u32 , u64 , 32 }
@@ -486,13 +490,11 @@ macro_rules! wmul_impl_large {
486
490
}
487
491
}
488
492
}
489
-
490
493
#[ cfg( not( feature = "i128_support" ) ) ]
491
494
wmul_impl_large ! { u64 , 32 }
492
495
#[ cfg( feature = "i128_support" ) ]
493
496
wmul_impl_large ! { u128 , 64 }
494
497
495
-
496
498
macro_rules! wmul_impl_usize {
497
499
( $ty: ty) => {
498
500
impl WideningMultiply for usize {
@@ -506,7 +508,6 @@ macro_rules! wmul_impl_usize {
506
508
}
507
509
}
508
510
}
509
-
510
511
#[ cfg( target_pointer_width = "32" ) ]
511
512
wmul_impl_usize ! { u32 }
512
513
#[ cfg( target_pointer_width = "64" ) ]
@@ -607,7 +608,9 @@ macro_rules! uniform_float_impl {
607
608
uniform_float_impl ! { f32 , 32 - 23 , next_u32 }
608
609
uniform_float_impl ! { f64 , 64 - 52 , next_u64 }
609
610
610
- /// Implementation of [`UniformSampler`] for `Duration`.
611
+
612
+
613
+ /// The back-end implementing [`UniformSampler`] for `Duration`.
611
614
///
612
615
/// Unless you are implementing [`UniformSampler`] for your own types, this type
613
616
/// should not be used directly, use [`Uniform`] instead.
0 commit comments