Skip to content

Commit e830dd4

Browse files
committed
shuf: Use impl return type in trait now that MSRV is high enough
1 parent cdd1052 commit e830dd4

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

src/uu/shuf/src/shuf.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,11 @@ trait Shufable {
243243
type Item: Writable;
244244
fn is_empty(&self) -> bool;
245245
fn choose(&self, rng: &mut WrappedRng) -> Self::Item;
246-
// This type shouldn't even be known. However, because we want to support
247-
// Rust 1.70, it is not possible to return "impl Iterator".
248-
// TODO: When the MSRV is raised, rewrite this to return "impl Iterator".
249-
type PartialShuffleIterator<'b>: Iterator<Item = Self::Item>
250-
where
251-
Self: 'b;
252246
fn partial_shuffle<'b>(
253247
&'b mut self,
254248
rng: &'b mut WrappedRng,
255249
amount: usize,
256-
) -> Self::PartialShuffleIterator<'b>;
250+
) -> impl Iterator<Item = Self::Item>;
257251
}
258252

259253
impl<'a> Shufable for Vec<&'a [u8]> {
@@ -267,15 +261,11 @@ impl<'a> Shufable for Vec<&'a [u8]> {
267261
// this is safe.
268262
(**self).choose(rng).unwrap()
269263
}
270-
type PartialShuffleIterator<'b>
271-
= std::iter::Copied<std::slice::Iter<'b, &'a [u8]>>
272-
where
273-
Self: 'b;
274264
fn partial_shuffle<'b>(
275265
&'b mut self,
276266
rng: &'b mut WrappedRng,
277267
amount: usize,
278-
) -> Self::PartialShuffleIterator<'b> {
268+
) -> impl Iterator<Item = Self::Item> {
279269
// Note: "copied()" only copies the reference, not the entire [u8].
280270
(**self).partial_shuffle(rng, amount).0.iter().copied()
281271
}
@@ -289,12 +279,11 @@ impl<'a> Shufable for Vec<&'a OsStr> {
289279
fn choose(&self, rng: &mut WrappedRng) -> Self::Item {
290280
(**self).choose(rng).unwrap()
291281
}
292-
type PartialShuffleIterator<'b> = std::iter::Copied<std::slice::Iter<'b, &'a OsStr>> where Self: 'b;
293282
fn partial_shuffle<'b>(
294283
&'b mut self,
295284
rng: &'b mut WrappedRng,
296285
amount: usize,
297-
) -> Self::PartialShuffleIterator<'b> {
286+
) -> impl Iterator<Item = Self::Item> {
298287
(**self).partial_shuffle(rng, amount).0.iter().copied()
299288
}
300289
}
@@ -307,15 +296,11 @@ impl Shufable for RangeInclusive<usize> {
307296
fn choose(&self, rng: &mut WrappedRng) -> usize {
308297
rng.random_range(self.clone())
309298
}
310-
type PartialShuffleIterator<'b>
311-
= NonrepeatingIterator<'b>
312-
where
313-
Self: 'b;
314299
fn partial_shuffle<'b>(
315300
&'b mut self,
316301
rng: &'b mut WrappedRng,
317302
amount: usize,
318-
) -> Self::PartialShuffleIterator<'b> {
303+
) -> impl Iterator<Item = Self::Item> {
319304
NonrepeatingIterator::new(self.clone(), rng, amount)
320305
}
321306
}

0 commit comments

Comments
 (0)