From e830dd45f09804bc5e2594b46d1662a39b279d18 Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Sun, 16 Mar 2025 13:42:17 +0100 Subject: [PATCH] shuf: Use impl return type in trait now that MSRV is high enough --- src/uu/shuf/src/shuf.rs | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index 56e26568b..ae35469a7 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -243,17 +243,11 @@ trait Shufable { type Item: Writable; fn is_empty(&self) -> bool; fn choose(&self, rng: &mut WrappedRng) -> Self::Item; - // This type shouldn't even be known. However, because we want to support - // Rust 1.70, it is not possible to return "impl Iterator". - // TODO: When the MSRV is raised, rewrite this to return "impl Iterator". - type PartialShuffleIterator<'b>: Iterator - where - Self: 'b; fn partial_shuffle<'b>( &'b mut self, rng: &'b mut WrappedRng, amount: usize, - ) -> Self::PartialShuffleIterator<'b>; + ) -> impl Iterator; } impl<'a> Shufable for Vec<&'a [u8]> { @@ -267,15 +261,11 @@ impl<'a> Shufable for Vec<&'a [u8]> { // this is safe. (**self).choose(rng).unwrap() } - type PartialShuffleIterator<'b> - = std::iter::Copied> - where - Self: 'b; fn partial_shuffle<'b>( &'b mut self, rng: &'b mut WrappedRng, amount: usize, - ) -> Self::PartialShuffleIterator<'b> { + ) -> impl Iterator { // Note: "copied()" only copies the reference, not the entire [u8]. (**self).partial_shuffle(rng, amount).0.iter().copied() } @@ -289,12 +279,11 @@ impl<'a> Shufable for Vec<&'a OsStr> { fn choose(&self, rng: &mut WrappedRng) -> Self::Item { (**self).choose(rng).unwrap() } - type PartialShuffleIterator<'b> = std::iter::Copied> where Self: 'b; fn partial_shuffle<'b>( &'b mut self, rng: &'b mut WrappedRng, amount: usize, - ) -> Self::PartialShuffleIterator<'b> { + ) -> impl Iterator { (**self).partial_shuffle(rng, amount).0.iter().copied() } } @@ -307,15 +296,11 @@ impl Shufable for RangeInclusive { fn choose(&self, rng: &mut WrappedRng) -> usize { rng.random_range(self.clone()) } - type PartialShuffleIterator<'b> - = NonrepeatingIterator<'b> - where - Self: 'b; fn partial_shuffle<'b>( &'b mut self, rng: &'b mut WrappedRng, amount: usize, - ) -> Self::PartialShuffleIterator<'b> { + ) -> impl Iterator { NonrepeatingIterator::new(self.clone(), rng, amount) } }