From 096a5dd5d69fe8a505507c93ab274b3fcacef583 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Sun, 15 Sep 2019 12:17:36 +0100 Subject: [PATCH] UniformSampler: add doc on usage of sample_single --- src/distributions/uniform.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs index 498cd5df701..b6125e73c39 100644 --- a/src/distributions/uniform.rs +++ b/src/distributions/uniform.rs @@ -245,6 +245,17 @@ pub trait UniformSampler: Sized { /// more optimal implementations for single usage may be provided via this /// method (which is the case for integers and floats). /// Results may not be identical. + /// + /// Note that to use this method in a generic context, the type needs to be + /// retrieved via `SampleUniform::Sampler` as follows: + /// ``` + /// use rand::{thread_rng, distributions::uniform::{SampleUniform, UniformSampler}}; + /// # #[allow(unused)] + /// fn sample_from_range(lb: T, ub: T) -> T { + /// let mut rng = thread_rng(); + /// ::Sampler::sample_single(lb, ub, &mut rng) + /// } + /// ``` fn sample_single(low: B1, high: B2, rng: &mut R) -> Self::X where B1: SampleBorrow + Sized,