Skip to content

Android789515/random_item

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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_owned_item(&messages);

Getting An Owned Value (Cloned)

use random_item::random_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);

About

A Cargo crate which allows retrieving a random item out of a sequential collection.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages