Skip to content

Commit 88c7f5e

Browse files
committed
rustfmt: where clauses and super traits
1 parent 477b470 commit 88c7f5e

File tree

16 files changed

+225
-127
lines changed

16 files changed

+225
-127
lines changed

rand_chacha/src/chacha.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ const STREAM_PARAM_NONCE: u32 = 1;
2020
const STREAM_PARAM_BLOCK: u32 = 0;
2121

2222
pub struct Array64<T>([T; 64]);
23-
impl<T> Default for Array64<T> where T: Default {
23+
impl<T> Default for Array64<T>
24+
where T: Default
25+
{
2426
fn default() -> Self {
2527
Self([T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(),
2628
T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(),
@@ -42,7 +44,9 @@ impl<T> AsMut<[T]> for Array64<T> {
4244
&mut self.0
4345
}
4446
}
45-
impl<T> Clone for Array64<T> where T: Copy + Default {
47+
impl<T> Clone for Array64<T>
48+
where T: Copy + Default
49+
{
4650
fn clone(&self) -> Self {
4751
let mut new = Self::default();
4852
new.0.copy_from_slice(&self.0);

rand_core/src/error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ impl Error {
3333
#[cfg(feature = "std")]
3434
#[inline]
3535
pub fn new<E>(err: E) -> Self
36-
where E: Into<Box<dyn std::error::Error + Send + Sync + 'static>>
37-
{
36+
where E: Into<Box<dyn std::error::Error + Send + Sync + 'static>> {
3837
Error { inner: err.into() }
3938
}
4039

rand_distr/src/dirichlet.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ impl fmt::Display for Error {
6161
impl error::Error for Error {}
6262

6363
impl<N: Float> Dirichlet<N>
64-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
64+
where
65+
StandardNormal: Distribution<N>,
66+
Exp1: Distribution<N>,
67+
Open01: Distribution<N>,
6568
{
6669
/// Construct a new `Dirichlet` with the given alpha parameter `alpha`.
6770
///
@@ -99,7 +102,10 @@ where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distributi
99102
}
100103

101104
impl<N: Float> Distribution<Vec<N>> for Dirichlet<N>
102-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
105+
where
106+
StandardNormal: Distribution<N>,
107+
Exp1: Distribution<N>,
108+
Open01: Distribution<N>,
103109
{
104110
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Vec<N> {
105111
let n = self.alpha.len();

rand_distr/src/gamma.rs

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ struct GammaLargeShape<N> {
115115
}
116116

117117
impl<N: Float> Gamma<N>
118-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
118+
where
119+
StandardNormal: Distribution<N>,
120+
Exp1: Distribution<N>,
121+
Open01: Distribution<N>,
119122
{
120123
/// Construct an object representing the `Gamma(shape, scale)`
121124
/// distribution.
@@ -140,7 +143,9 @@ where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distributi
140143
}
141144

142145
impl<N: Float> GammaSmallShape<N>
143-
where StandardNormal: Distribution<N>, Open01: Distribution<N>
146+
where
147+
StandardNormal: Distribution<N>,
148+
Open01: Distribution<N>,
144149
{
145150
fn new_raw(shape: N, scale: N) -> GammaSmallShape<N> {
146151
GammaSmallShape {
@@ -151,7 +156,9 @@ where StandardNormal: Distribution<N>, Open01: Distribution<N>
151156
}
152157

153158
impl<N: Float> GammaLargeShape<N>
154-
where StandardNormal: Distribution<N>, Open01: Distribution<N>
159+
where
160+
StandardNormal: Distribution<N>,
161+
Open01: Distribution<N>,
155162
{
156163
fn new_raw(shape: N, scale: N) -> GammaLargeShape<N> {
157164
let d = shape - N::from(1. / 3.);
@@ -164,7 +171,10 @@ where StandardNormal: Distribution<N>, Open01: Distribution<N>
164171
}
165172

166173
impl<N: Float> Distribution<N> for Gamma<N>
167-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
174+
where
175+
StandardNormal: Distribution<N>,
176+
Exp1: Distribution<N>,
177+
Open01: Distribution<N>,
168178
{
169179
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> N {
170180
match self.repr {
@@ -175,7 +185,9 @@ where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distributi
175185
}
176186
}
177187
impl<N: Float> Distribution<N> for GammaSmallShape<N>
178-
where StandardNormal: Distribution<N>, Open01: Distribution<N>
188+
where
189+
StandardNormal: Distribution<N>,
190+
Open01: Distribution<N>,
179191
{
180192
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> N {
181193
let u: N = rng.sample(Open01);
@@ -184,7 +196,9 @@ where StandardNormal: Distribution<N>, Open01: Distribution<N>
184196
}
185197
}
186198
impl<N: Float> Distribution<N> for GammaLargeShape<N>
187-
where StandardNormal: Distribution<N>, Open01: Distribution<N>
199+
where
200+
StandardNormal: Distribution<N>,
201+
Open01: Distribution<N>,
188202
{
189203
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> N {
190204
// Marsaglia & Tsang method, 2000
@@ -259,7 +273,10 @@ enum ChiSquaredRepr<N> {
259273
}
260274

261275
impl<N: Float> ChiSquared<N>
262-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
276+
where
277+
StandardNormal: Distribution<N>,
278+
Exp1: Distribution<N>,
279+
Open01: Distribution<N>,
263280
{
264281
/// Create a new chi-squared distribution with degrees-of-freedom
265282
/// `k`.
@@ -276,7 +293,10 @@ where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distributi
276293
}
277294
}
278295
impl<N: Float> Distribution<N> for ChiSquared<N>
279-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
296+
where
297+
StandardNormal: Distribution<N>,
298+
Exp1: Distribution<N>,
299+
Open01: Distribution<N>,
280300
{
281301
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> N {
282302
match self.repr {
@@ -335,7 +355,10 @@ impl fmt::Display for FisherFError {
335355
impl error::Error for FisherFError {}
336356

337357
impl<N: Float> FisherF<N>
338-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
358+
where
359+
StandardNormal: Distribution<N>,
360+
Exp1: Distribution<N>,
361+
Open01: Distribution<N>,
339362
{
340363
/// Create a new `FisherF` distribution, with the given parameter.
341364
pub fn new(m: N, n: N) -> Result<FisherF<N>, FisherFError> {
@@ -354,7 +377,10 @@ where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distributi
354377
}
355378
}
356379
impl<N: Float> Distribution<N> for FisherF<N>
357-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
380+
where
381+
StandardNormal: Distribution<N>,
382+
Exp1: Distribution<N>,
383+
Open01: Distribution<N>,
358384
{
359385
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> N {
360386
self.numer.sample(rng) / self.denom.sample(rng) * self.dof_ratio
@@ -380,7 +406,10 @@ pub struct StudentT<N> {
380406
}
381407

382408
impl<N: Float> StudentT<N>
383-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
409+
where
410+
StandardNormal: Distribution<N>,
411+
Exp1: Distribution<N>,
412+
Open01: Distribution<N>,
384413
{
385414
/// Create a new Student t distribution with `n` degrees of
386415
/// freedom.
@@ -392,7 +421,10 @@ where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distributi
392421
}
393422
}
394423
impl<N: Float> Distribution<N> for StudentT<N>
395-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
424+
where
425+
StandardNormal: Distribution<N>,
426+
Exp1: Distribution<N>,
427+
Open01: Distribution<N>,
396428
{
397429
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> N {
398430
let norm: N = rng.sample(StandardNormal);
@@ -438,7 +470,10 @@ impl fmt::Display for BetaError {
438470
impl error::Error for BetaError {}
439471

440472
impl<N: Float> Beta<N>
441-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
473+
where
474+
StandardNormal: Distribution<N>,
475+
Exp1: Distribution<N>,
476+
Open01: Distribution<N>,
442477
{
443478
/// Construct an object representing the `Beta(alpha, beta)`
444479
/// distribution.
@@ -453,7 +488,10 @@ where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distributi
453488
}
454489

455490
impl<N: Float> Distribution<N> for Beta<N>
456-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
491+
where
492+
StandardNormal: Distribution<N>,
493+
Exp1: Distribution<N>,
494+
Open01: Distribution<N>,
457495
{
458496
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> N {
459497
let x = self.gamma_a.sample(rng);

rand_distr/src/pert.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ impl fmt::Display for PertError {
6161
impl error::Error for PertError {}
6262

6363
impl<N: Float> Pert<N>
64-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
64+
where
65+
StandardNormal: Distribution<N>,
66+
Exp1: Distribution<N>,
67+
Open01: Distribution<N>,
6568
{
6669
/// Set up the PERT distribution with defined `min`, `max` and `mode`.
6770
///
@@ -99,7 +102,10 @@ where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distributi
99102
}
100103

101104
impl<N: Float> Distribution<N> for Pert<N>
102-
where StandardNormal: Distribution<N>, Exp1: Distribution<N>, Open01: Distribution<N>
105+
where
106+
StandardNormal: Distribution<N>,
107+
Exp1: Distribution<N>,
108+
Open01: Distribution<N>,
103109
{
104110
#[inline]
105111
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> N {

rand_distr/src/utils.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@ use rand::Rng;
2121
///
2222
/// The bounds and methods are based purely on internal
2323
/// requirements, and will change as needed.
24-
pub trait Float: Copy + Sized + cmp::PartialOrd
24+
pub trait Float:
25+
Copy
26+
+ Sized
27+
+ cmp::PartialOrd
2528
+ ops::Neg<Output = Self>
2629
+ ops::Add<Output = Self>
2730
+ ops::Sub<Output = Self>
2831
+ ops::Mul<Output = Self>
2932
+ ops::Div<Output = Self>
30-
+ ops::AddAssign + ops::SubAssign + ops::MulAssign + ops::DivAssign
33+
+ ops::AddAssign
34+
+ ops::SubAssign
35+
+ ops::MulAssign
36+
+ ops::DivAssign
3137
{
3238
/// The constant π
3339
fn pi() -> Self;

src/distributions/integer.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,8 @@ mod tests {
187187

188188
#[test]
189189
fn value_stability() {
190-
fn test_samples<T: Copy + core::fmt::Debug + PartialEq>(
191-
zero: T, expected: &[T]
192-
)
193-
where Standard: Distribution<T>
194-
{
190+
fn test_samples<T: Copy + core::fmt::Debug + PartialEq>(zero: T, expected: &[T])
191+
where Standard: Distribution<T> {
195192
let mut rng = crate::test::rng(807);
196193
let mut buf = [zero; 3];
197194
for x in &mut buf {

src/distributions/mod.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ pub trait Distribution<T> {
220220
/// }
221221
/// ```
222222
fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
223-
where R: Rng, Self: Sized
223+
where
224+
R: Rng,
225+
Self: Sized,
224226
{
225227
DistIter {
226228
distr: self,
@@ -252,7 +254,9 @@ pub struct DistIter<D, R, T> {
252254
}
253255

254256
impl<D, R, T> Iterator for DistIter<D, R, T>
255-
where D: Distribution<T>, R: Rng
257+
where
258+
D: Distribution<T>,
259+
R: Rng,
256260
{
257261
type Item = T;
258262

@@ -270,11 +274,19 @@ impl<D, R, T> Iterator for DistIter<D, R, T>
270274
}
271275

272276
impl<D, R, T> iter::FusedIterator for DistIter<D, R, T>
273-
where D: Distribution<T>, R: Rng {}
277+
where
278+
D: Distribution<T>,
279+
R: Rng,
280+
{
281+
}
274282

275283
#[cfg(features = "nightly")]
276284
impl<D, R, T> iter::TrustedLen for DistIter<D, R, T>
277-
where D: Distribution<T>, R: Rng {}
285+
where
286+
D: Distribution<T>,
287+
R: Rng,
288+
{
289+
}
278290

279291

280292
/// A generic random value distribution, implemented for many primitive types.

src/distributions/other.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ macro_rules! array_impl {
155155

156156
array_impl! {32, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,}
157157

158-
impl<T> Distribution<Option<T>> for Standard where Standard: Distribution<T> {
158+
impl<T> Distribution<Option<T>> for Standard
159+
where Standard: Distribution<T>
160+
{
159161
#[inline]
160162
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Option<T> {
161163
// UFCS is needed here: https://github.com/rust-lang/rust/issues/24066
@@ -167,7 +169,9 @@ impl<T> Distribution<Option<T>> for Standard where Standard: Distribution<T> {
167169
}
168170
}
169171

170-
impl<T> Distribution<Wrapping<T>> for Standard where Standard: Distribution<T> {
172+
impl<T> Distribution<Wrapping<T>> for Standard
173+
where Standard: Distribution<T>
174+
{
171175
#[inline]
172176
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Wrapping<T> {
173177
Wrapping(rng.gen())

0 commit comments

Comments
 (0)