| Crates.io | trekname |
| lib.rs | trekname |
| version | 0.1.2 |
| created_at | 2025-02-21 11:07:51.6878+00 |
| updated_at | 2025-02-21 12:20:10.122647+00 |
| description | A library containing Star Trek character names and descriptions |
| homepage | |
| repository | https://github.com/rakki194/trekname |
| max_upload_size | |
| id | 1563951 |
| size | 42,462 |
A Rust library containing Star Trek character names and descriptions from various series including The Original Series, The Next Generation, Deep Space Nine, Voyager, Enterprise, and Discovery.
phf_mapAdd this to your Cargo.toml:
[dependencies]
trekname = "0.1.2"
use trekname::{get_description, character_exists, get_all_names};
fn main() {
// Get a character's description
if let Some(description) = get_description("Kirk") {
println!("Kirk: {}", description);
}
// Check if a character exists
if character_exists("Picard") {
println!("Picard exists in the database!");
}
// Get all character names
let names = get_all_names();
println!("Total characters: {}", names.len());
}
To get random characters, first add the rand crate to your Cargo.toml:
[dependencies]
trekname = "0.1.1"
rand = "0.8"
Then you can use this code to get a random character:
use trekname::{get_all_names, get_description};
use rand::seq::SliceRandom;
fn main() {
let names = get_all_names();
if let Some(random_name) = names.choose(&mut rand::thread_rng()) {
println!("Random Star Trek character: {}", random_name);
if let Some(description) = get_description(random_name) {
println!("Description: {}", description);
}
}
}
This will randomly select a character from the database and display their name and description.
get_description(name: &str) -> Option<&'static str>: Returns the description for a given character name, if it existscharacter_exists(name: &str) -> bool: Returns true if the character exists in the databaseget_all_names() -> Vec<&'static str>: Returns a vector of all character namesTREK_DESCRIPTIONS: A static phf::Map containing all character names and descriptionsThis project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.