Skip to content

Commit cddc934

Browse files
committed
Rename UniformImpl → UniformSampler
1 parent 634d4cb commit cddc934

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

src/distributions/uniform.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
//! # Extending `Uniform` to support a custom type
4646
//!
4747
//! To extend [`Uniform`] to support your own types, write a back-end which
48-
//! implements the [`UniformImpl`] trait, then implement the [`SampleUniform`]
48+
//! implements the [`UniformSampler`] trait, then implement the [`SampleUniform`]
4949
//! helper trait to "register" your back-end. See the `MyF32` example below.
5050
//!
5151
//! At a minimum, the back-end needs to store any parameters needed for sampling
@@ -56,7 +56,7 @@
5656
//! use rand::{Rng, thread_rng};
5757
//! use rand::distributions::Distribution;
5858
//! use rand::distributions::uniform::{Uniform, SampleUniform};
59-
//! use rand::distributions::uniform::{UniformImpl, UniformFloat};
59+
//! use rand::distributions::uniform::{UniformSampler, UniformFloat};
6060
//!
6161
//! #[derive(Clone, Copy, PartialEq, PartialOrd)]
6262
//! struct MyF32(f32);
@@ -65,23 +65,23 @@
6565
//! struct UniformMyF32 {
6666
//! inner: UniformFloat<f32>,
6767
//! }
68-
//! impl UniformImpl for UniformMyF32 {
68+
//! impl UniformSampler for UniformMyF32 {
6969
//! type X = MyF32;
7070
//! fn new(low: Self::X, high: Self::X) -> Self {
7171
//! UniformMyF32 {
7272
//! inner: UniformFloat::<f32>::new(low.0, high.0),
7373
//! }
7474
//! }
7575
//! fn new_inclusive(low: Self::X, high: Self::X) -> Self {
76-
//! UniformImpl::new(low, high)
76+
//! UniformSampler::new(low, high)
7777
//! }
7878
//! fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
7979
//! MyF32(self.inner.sample(rng))
8080
//! }
8181
//! }
8282
//!
8383
//! impl SampleUniform for MyF32 {
84-
//! type Impl = UniformMyF32;
84+
//! type Sampler = UniformMyF32;
8585
//! }
8686
//!
8787
//! let (low, high) = (MyF32(17.0f32), MyF32(22.0f32));
@@ -93,7 +93,7 @@
9393
//! [`Uniform::sample_single`]: struct.Uniform.html#method.sample_single
9494
//! [`Rng::gen_range`]: ../../trait.Rng.html#method.gen_range
9595
//! [`SampleUniform`]: trait.SampleUniform.html
96-
//! [`UniformImpl`]: trait.UniformImpl.html
96+
//! [`UniformSampler`]: trait.UniformSampler.html
9797
//! [`UniformInt`]: struct.UniformInt.html
9898
//! [`UniformFloat`]: struct.UniformFloat.html
9999
//! [`UniformDuration`]: struct.UniformDuration.html
@@ -156,29 +156,29 @@ use distributions::float::IntoFloat;
156156
/// [`sample_single`]: struct.Uniform.html#method.sample_single
157157
#[derive(Clone, Copy, Debug)]
158158
pub struct Uniform<X: SampleUniform> {
159-
inner: X::Impl,
159+
inner: X::Sampler,
160160
}
161161

162162
impl<X: SampleUniform> Uniform<X> {
163163
/// Create a new `Uniform` instance which samples uniformly from the half
164164
/// open range `[low, high)` (excluding `high`). Panics if `low >= high`.
165165
pub fn new(low: X, high: X) -> Uniform<X> {
166166
assert!(low < high, "Uniform::new called with `low >= high`");
167-
Uniform { inner: X::Impl::new(low, high) }
167+
Uniform { inner: X::Sampler::new(low, high) }
168168
}
169169

170170
/// Create a new `Uniform` instance which samples uniformly from the closed
171171
/// range `[low, high]` (inclusive). Panics if `low > high`.
172172
pub fn new_inclusive(low: X, high: X) -> Uniform<X> {
173173
assert!(low <= high, "Uniform::new_inclusive called with `low > high`");
174-
Uniform { inner: X::Impl::new_inclusive(low, high) }
174+
Uniform { inner: X::Sampler::new_inclusive(low, high) }
175175
}
176176

177177
/// Sample a single value uniformly from `[low, high)`.
178178
/// Panics if `low >= high`.
179179
pub fn sample_single<R: Rng + ?Sized>(low: X, high: X, rng: &mut R) -> X {
180180
assert!(low < high, "Uniform::sample_single called with low >= high");
181-
X::Impl::sample_single(low, high, rng)
181+
X::Sampler::sample_single(low, high, rng)
182182
}
183183
}
184184

@@ -189,17 +189,17 @@ impl<X: SampleUniform> Distribution<X> for Uniform<X> {
189189
}
190190

191191
/// Helper trait for creating objects using the correct implementation of
192-
/// [`UniformImpl`] for the sampling type.
192+
/// [`UniformSampler`] for the sampling type.
193193
///
194194
/// See the [module documentation] on how to implement [`Uniform`] range
195195
/// sampling for a custom type.
196196
///
197-
/// [`UniformImpl`]: trait.UniformImpl.html
197+
/// [`UniformSampler`]: trait.UniformSampler.html
198198
/// [module documentation]: index.html
199199
/// [`Uniform`]: struct.Uniform.html
200200
pub trait SampleUniform: PartialOrd+Sized {
201-
/// The `UniformImpl` implementation supporting type `X`.
202-
type Impl: UniformImpl<X = Self>;
201+
/// The `UniformSampler` implementation supporting type `X`.
202+
type Sampler: UniformSampler<X = Self>;
203203
}
204204

205205
/// Helper trait handling actual uniform sampling.
@@ -212,8 +212,8 @@ pub trait SampleUniform: PartialOrd+Sized {
212212
///
213213
/// [module documentation]: index.html
214214
/// [`Uniform`]: struct.Uniform.html
215-
/// [`sample_single`]: struct.UniformImpl.html#method.sample_single
216-
pub trait UniformImpl: Sized {
215+
/// [`sample_single`]: struct.UniformSampler.html#method.sample_single
216+
pub trait UniformSampler: Sized {
217217
/// The type sampled by this implementation.
218218
type X: PartialOrd;
219219

@@ -243,19 +243,19 @@ pub trait UniformImpl: Sized {
243243
///
244244
/// Via this method, implementations can provide a method optimized for
245245
/// sampling only a single value from the specified range. The default
246-
/// implementation simply calls `UniformImpl::new` then `sample` on the
246+
/// implementation simply calls `UniformSampler::new` then `sample` on the
247247
/// result.
248248
fn sample_single<R: Rng + ?Sized>(low: Self::X, high: Self::X, rng: &mut R)
249249
-> Self::X
250250
{
251-
let uniform: Self = UniformImpl::new(low, high);
251+
let uniform: Self = UniformSampler::new(low, high);
252252
uniform.sample(rng)
253253
}
254254
}
255255

256-
/// The back-end implementing [`UniformImpl`] for integer types.
256+
/// The back-end implementing [`UniformSampler`] for integer types.
257257
///
258-
/// Unless you are implementing [`UniformImpl`] for your own type, this type
258+
/// Unless you are implementing [`UniformSampler`] for your own type, this type
259259
/// should not be used directly, use [`Uniform`] instead.
260260
///
261261
/// # Implementation notes
@@ -295,7 +295,7 @@ pub trait UniformImpl: Sized {
295295
/// multiply by `range`, the result is in the high word. Then comparing the low
296296
/// word against `zone` makes sure our distribution is uniform.
297297
///
298-
/// [`UniformImpl`]: trait.UniformImpl.html
298+
/// [`UniformSampler`]: trait.UniformSampler.html
299299
/// [`Uniform`]: struct.Uniform.html
300300
#[derive(Clone, Copy, Debug)]
301301
pub struct UniformInt<X> {
@@ -308,10 +308,10 @@ macro_rules! uniform_int_impl {
308308
($ty:ty, $signed:ty, $unsigned:ident,
309309
$i_large:ident, $u_large:ident) => {
310310
impl SampleUniform for $ty {
311-
type Impl = UniformInt<$ty>;
311+
type Sampler = UniformInt<$ty>;
312312
}
313313

314-
impl UniformImpl for UniformInt<$ty> {
314+
impl UniformSampler for UniformInt<$ty> {
315315
// We play free and fast with unsigned vs signed here
316316
// (when $ty is signed), but that's fine, since the
317317
// contract of this macro is for $ty and $unsigned to be
@@ -322,7 +322,7 @@ macro_rules! uniform_int_impl {
322322
#[inline] // if the range is constant, this helps LLVM to do the
323323
// calculations at compile-time.
324324
fn new(low: Self::X, high: Self::X) -> Self {
325-
UniformImpl::new_inclusive(low, high - 1)
325+
UniformSampler::new_inclusive(low, high - 1)
326326
}
327327

328328
#[inline] // if the range is constant, this helps LLVM to do the
@@ -510,9 +510,9 @@ wmul_impl_usize! { u64 }
510510

511511

512512

513-
/// The back-end implementing [`UniformImpl`] for floating-point types.
513+
/// The back-end implementing [`UniformSampler`] for floating-point types.
514514
///
515-
/// Unless you are implementing [`UniformImpl`] for your own type, this type
515+
/// Unless you are implementing [`UniformSampler`] for your own type, this type
516516
/// should not be used directly, use [`Uniform`] instead.
517517
///
518518
/// # Implementation notes
@@ -530,9 +530,9 @@ wmul_impl_usize! { u64 }
530530
/// because the boundaries of a floats range are a bit of a fuzzy concept due to
531531
/// rounding errors.
532532
///
533-
/// [`UniformImpl`]: trait.UniformImpl.html
534-
/// [`new`]: trait.UniformImpl.html#tymethod.new
535-
/// [`new_inclusive`]: trait.UniformImpl.html#tymethod.new_inclusive
533+
/// [`UniformSampler`]: trait.UniformSampler.html
534+
/// [`new`]: trait.UniformSampler.html#tymethod.new
535+
/// [`new_inclusive`]: trait.UniformSampler.html#tymethod.new_inclusive
536536
/// [`Uniform`]: struct.Uniform.html
537537
/// [`Standard`]: ../struct.Standard.html
538538
#[derive(Clone, Copy, Debug)]
@@ -544,10 +544,10 @@ pub struct UniformFloat<X> {
544544
macro_rules! uniform_float_impl {
545545
($ty:ty, $bits_to_discard:expr, $next_u:ident) => {
546546
impl SampleUniform for $ty {
547-
type Impl = UniformFloat<$ty>;
547+
type Sampler = UniformFloat<$ty>;
548548
}
549549

550-
impl UniformImpl for UniformFloat<$ty> {
550+
impl UniformSampler for UniformFloat<$ty> {
551551
type X = $ty;
552552

553553
fn new(low: Self::X, high: Self::X) -> Self {
@@ -560,7 +560,7 @@ macro_rules! uniform_float_impl {
560560
}
561561

562562
fn new_inclusive(low: Self::X, high: Self::X) -> Self {
563-
UniformImpl::new(low, high)
563+
UniformSampler::new(low, high)
564564
}
565565

566566
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
@@ -594,12 +594,12 @@ macro_rules! uniform_float_impl {
594594
uniform_float_impl! { f32, 32 - 23, next_u32 }
595595
uniform_float_impl! { f64, 64 - 52, next_u64 }
596596

597-
/// Implementation of [`UniformImpl`] for `Duration`.
597+
/// Implementation of [`UniformSampler`] for `Duration`.
598598
///
599-
/// Unless you are implementing [`UniformImpl`] for your own types, this type
599+
/// Unless you are implementing [`UniformSampler`] for your own types, this type
600600
/// should not be used directly, use [`Uniform`] instead.
601601
///
602-
/// [`UniformImpl`]: trait.UniformImpl.html
602+
/// [`UniformSampler`]: trait.UniformSampler.html
603603
/// [`Uniform`]: struct.Uniform.html
604604
#[cfg(feature = "std")]
605605
#[derive(Clone, Copy, Debug)]
@@ -622,11 +622,11 @@ enum UniformDurationMode {
622622

623623
#[cfg(feature = "std")]
624624
impl SampleUniform for Duration {
625-
type Impl = UniformDuration;
625+
type Sampler = UniformDuration;
626626
}
627627

628628
#[cfg(feature = "std")]
629-
impl UniformImpl for UniformDuration {
629+
impl UniformSampler for UniformDuration {
630630
type X = Duration;
631631

632632
#[inline]
@@ -686,7 +686,7 @@ impl UniformImpl for UniformDuration {
686686
#[cfg(test)]
687687
mod tests {
688688
use Rng;
689-
use distributions::uniform::{Uniform, UniformImpl, UniformFloat, SampleUniform};
689+
use distributions::uniform::{Uniform, UniformSampler, UniformFloat, SampleUniform};
690690

691691
#[should_panic]
692692
#[test]
@@ -819,22 +819,22 @@ mod tests {
819819
struct UniformMyF32 {
820820
inner: UniformFloat<f32>,
821821
}
822-
impl UniformImpl for UniformMyF32 {
822+
impl UniformSampler for UniformMyF32 {
823823
type X = MyF32;
824824
fn new(low: Self::X, high: Self::X) -> Self {
825825
UniformMyF32 {
826826
inner: UniformFloat::<f32>::new(low.x, high.x),
827827
}
828828
}
829829
fn new_inclusive(low: Self::X, high: Self::X) -> Self {
830-
UniformImpl::new(low, high)
830+
UniformSampler::new(low, high)
831831
}
832832
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
833833
MyF32 { x: self.inner.sample(rng) }
834834
}
835835
}
836836
impl SampleUniform for MyF32 {
837-
type Impl = UniformMyF32;
837+
type Sampler = UniformMyF32;
838838
}
839839

840840
let (low, high) = (MyF32{ x: 17.0f32 }, MyF32{ x: 22.0f32 });

0 commit comments

Comments
 (0)