🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

fastrand

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastrand - cargo Package Compare versions

Comparing version
2.2.0
to
2.3.0
+1
-1
.cargo_vcs_info.json
{
"git": {
"sha1": "1b93479b8ea275997771df15aa4dbd54ee01bd6d"
"sha1": "8419f8916f08c63572b4f7cbdc07cec94c1fc5ed"
},
"path_in_vcs": ""
}

@@ -16,6 +16,7 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO

name = "fastrand"
version = "2.2.0"
version = "2.3.0"
authors = ["Stjepan Glavina <stjepang@gmail.com>"]
build = false
exclude = ["/.*"]
autolib = false
autobins = false

@@ -22,0 +23,0 @@ autoexamples = false

@@ -0,1 +1,5 @@

# Version 2.3.0
- Accept `IntoIterator` in `choose_multiple` functions instead of just `Iterator`. (#92)
# Version 2.2.0

@@ -2,0 +6,0 @@

@@ -46,3 +46,3 @@ # fastrand

```rust
fastrand::choose_multiple(vec![1, 4, 5].iter(), 2);
fastrand::choose_multiple([1, 4, 5], 2);
fastrand::choose_multiple(0..20, 12);

@@ -49,0 +49,0 @@ ```

@@ -184,4 +184,4 @@ //! A global, thread-local random number generator.

/// Collects `amount` values at random from the iterator into a vector.
pub fn choose_multiple<T: Iterator>(source: T, amount: usize) -> Vec<T::Item> {
/// Collects `amount` values at random from the iterable into a vector.
pub fn choose_multiple<I: IntoIterator>(source: I, amount: usize) -> Vec<I::Item> {
with_rng(|rng| rng.choose_multiple(source, amount))

@@ -188,0 +188,0 @@ }

@@ -35,3 +35,3 @@ //! A simple and fast random number generator.

//! ```
//! fastrand::choose_multiple(vec![1, 4, 5].iter(), 2);
//! fastrand::choose_multiple([1, 4, 5], 2);
//! fastrand::choose_multiple(0..20, 12);

@@ -382,16 +382,17 @@ //! ```

/// Collects `amount` values at random from the iterator into a vector.
/// Collects `amount` values at random from the iterable into a vector.
///
/// The length of the returned vector equals `amount` unless the iterator
/// The length of the returned vector equals `amount` unless the iterable
/// contains insufficient elements, in which case it equals the number of
/// elements available.
///
/// Complexity is `O(n)` where `n` is the length of the iterator.
/// Complexity is `O(n)` where `n` is the length of the iterable.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn choose_multiple<T: Iterator>(&mut self, mut source: T, amount: usize) -> Vec<T::Item> {
pub fn choose_multiple<I: IntoIterator>(&mut self, source: I, amount: usize) -> Vec<I::Item> {
// Adapted from: https://docs.rs/rand/latest/rand/seq/trait.IteratorRandom.html#method.choose_multiple
let mut reservoir = Vec::with_capacity(amount);
let mut iter = source.into_iter();
reservoir.extend(source.by_ref().take(amount));
reservoir.extend(iter.by_ref().take(amount));

@@ -403,3 +404,3 @@ // Continue unless the iterator was exhausted

if reservoir.len() == amount {
for (i, elem) in source.enumerate() {
for (i, elem) in iter.enumerate() {
let end = i + 1 + amount;

@@ -406,0 +407,0 @@ let k = self.usize(0..end);

Sorry, the diff of this file is not supported yet