random_item

Crates.iorandom_item
lib.rsrandom_item
version0.1.8
created_at2025-06-07 07:44:27.365684+00
updated_at2026-01-15 06:53:26.75463+00
descriptionEasily reference or clone a random item from a sequential collection.
homepagehttps://codeberg.org/Android789515/random_item
repositoryhttps://codeberg.org/Android789515/random_item
max_upload_size
id1703774
size8,624
(Android789515)

documentation

https://docs.rs/random_item/latest/random_item/

README

Random Item

Get a random item out of a sequential collection.

Getting A Reference

use random_item::random_item;

let messages = Vec::from([
   String::from("Hello, "),
   String::from("fellow "),
   String::from("Rustaceans!"),
]);

let random_message = random_item(&messages);

Getting An Owned Value (Cloned)

use random_item::random_owned_item;

#[derive(PartialEq, Clone)]
struct Shape {
   sides: u32,
}

let shapes = [
   Shape { sides: 1 },
   Shape { sides: 1 },
   Shape { sides: 2 },
   Shape { sides: 3 },
   Shape { sides: 5 },
   Shape { sides: 8 },
   Shape { sides: 13 },
   Shape { sides: 21 },
];

let random_shape = random_owned_item(&shapes);
Commit count: 0

cargo fmt