Skip to content

Commit 88b460e

Browse files
committed
Rename struct SliceChooseIter -> IndexedSamples
1 parent 8f6a8c5 commit 88b460e

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/seq/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ mod index_;
4040
pub use crate::distr::weighted::Error as WeightError;
4141
pub use iterator::IteratorRandom;
4242
#[cfg(feature = "alloc")]
43+
pub use slice::IndexedSamples;
44+
#[allow(deprecated)]
45+
#[cfg(feature = "alloc")]
4346
pub use slice::SliceChooseIter;
4447
pub use slice::{IndexedMutRandom, IndexedRandom, SliceRandom};
4548

src/seq/slice.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ pub trait IndexedRandom: Index<usize> {
8787
/// }
8888
/// ```
8989
#[cfg(feature = "alloc")]
90-
fn sample<R>(&self, rng: &mut R, amount: usize) -> SliceChooseIter<Self, Self::Output>
90+
fn sample<R>(&self, rng: &mut R, amount: usize) -> IndexedSamples<Self, Self::Output>
9191
where
9292
Self::Output: Sized,
9393
R: Rng + ?Sized,
9494
{
9595
let amount = core::cmp::min(amount, self.len());
96-
SliceChooseIter {
96+
IndexedSamples {
9797
slice: self,
9898
_phantom: Default::default(),
9999
indices: index::sample(rng, self.len(), amount).into_iter(),
@@ -209,15 +209,15 @@ pub trait IndexedRandom: Index<usize> {
209209
rng: &mut R,
210210
amount: usize,
211211
weight: F,
212-
) -> Result<SliceChooseIter<Self, Self::Output>, WeightError>
212+
) -> Result<IndexedSamples<Self, Self::Output>, WeightError>
213213
where
214214
Self::Output: Sized,
215215
R: Rng + ?Sized,
216216
F: Fn(&Self::Output) -> X,
217217
X: Into<f64>,
218218
{
219219
let amount = core::cmp::min(amount, self.len());
220-
Ok(SliceChooseIter {
220+
Ok(IndexedSamples {
221221
slice: self,
222222
_phantom: Default::default(),
223223
indices: index::sample_weighted(
@@ -233,7 +233,7 @@ pub trait IndexedRandom: Index<usize> {
233233
/// Deprecated: use [`Self::sample`] instead
234234
#[cfg(feature = "alloc")]
235235
#[deprecated(since = "0.9.2", note = "Renamed to `sample`")]
236-
fn choose_multiple<R>(&self, rng: &mut R, amount: usize) -> SliceChooseIter<Self, Self::Output>
236+
fn choose_multiple<R>(&self, rng: &mut R, amount: usize) -> IndexedSamples<Self, Self::Output>
237237
where
238238
Self::Output: Sized,
239239
R: Rng + ?Sized,
@@ -259,7 +259,7 @@ pub trait IndexedRandom: Index<usize> {
259259
rng: &mut R,
260260
amount: usize,
261261
weight: F,
262-
) -> Result<SliceChooseIter<Self, Self::Output>, WeightError>
262+
) -> Result<IndexedSamples<Self, Self::Output>, WeightError>
263263
where
264264
Self::Output: Sized,
265265
R: Rng + ?Sized,
@@ -454,14 +454,14 @@ impl<T> SliceRandom for [T] {
454454
/// [`IndexedRandom::sample`](trait.IndexedRandom.html#tymethod.sample).
455455
#[cfg(feature = "alloc")]
456456
#[derive(Debug)]
457-
pub struct SliceChooseIter<'a, S: ?Sized + 'a, T: 'a> {
457+
pub struct IndexedSamples<'a, S: ?Sized + 'a, T: 'a> {
458458
slice: &'a S,
459459
_phantom: core::marker::PhantomData<T>,
460460
indices: index::IndexVecIntoIter,
461461
}
462462

463463
#[cfg(feature = "alloc")]
464-
impl<'a, S: Index<usize, Output = T> + ?Sized + 'a, T: 'a> Iterator for SliceChooseIter<'a, S, T> {
464+
impl<'a, S: Index<usize, Output = T> + ?Sized + 'a, T: 'a> Iterator for IndexedSamples<'a, S, T> {
465465
type Item = &'a T;
466466

467467
fn next(&mut self) -> Option<Self::Item> {
@@ -476,13 +476,18 @@ impl<'a, S: Index<usize, Output = T> + ?Sized + 'a, T: 'a> Iterator for SliceCho
476476

477477
#[cfg(feature = "alloc")]
478478
impl<'a, S: Index<usize, Output = T> + ?Sized + 'a, T: 'a> ExactSizeIterator
479-
for SliceChooseIter<'a, S, T>
479+
for IndexedSamples<'a, S, T>
480480
{
481481
fn len(&self) -> usize {
482482
self.indices.len()
483483
}
484484
}
485485

486+
/// Deprecated: renamed to [`IndexedSamples`]
487+
#[cfg(feature = "alloc")]
488+
#[deprecated(since = "0.9.2", note = "Renamed to `IndexedSamples`")]
489+
pub type SliceChooseIter<'a, S, T> = IndexedSamples<'a, S, T>;
490+
486491
#[cfg(test)]
487492
mod test {
488493
use super::*;

0 commit comments

Comments
 (0)