From aba32d473e50d0393952649f38a59070273c1035 Mon Sep 17 00:00:00 2001 From: Musselman Date: Tue, 13 Feb 2024 11:35:44 -0600 Subject: [PATCH] Add v1 --- Cargo.lock | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 + src/main.rs | 48 ++++++++++++++++++- 3 files changed, 184 insertions(+), 2 deletions(-) create mode 100644 Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..67cf231 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,136 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "regex" +version = "1.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "version_name_generator" +version = "0.1.0" +dependencies = [ + "Inflector", + "rand", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/Cargo.toml b/Cargo.toml index c5507ea..dc3a609 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,5 @@ authors = ["James Musselman "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +rand = "0.8.4" +Inflector = "*" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e7a11a9..be00681 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,47 @@ -fn main() { - println!("Hello, world!"); +use std::fs::File; +use std::io::{self, BufRead}; +use inflector::Inflector; +use rand::thread_rng; +use rand::seq::SliceRandom; + +fn main() -> io::Result<()> { + // Open the files + let animal_file = File::open("animals.txt")?; + let adj_file = File::open("adj.txt")?; + + let animal_reader = io::BufReader::new(animal_file); + let adj_reader = io::BufReader::new(adj_file); + + // Read each line into a vector + let animal_lines: Vec = animal_reader.lines().filter_map(|line| line.ok()).collect(); + let adj_lines: Vec = adj_reader.lines().filter_map(|line| line.ok()).collect(); + + // Check if the animal file is empty + if animal_lines.is_empty() { + println!("Animal file is empty"); + return Ok(()); + } + + // Check if the adjective file is empty + if adj_lines.is_empty() { + println!("Adjective file is empty"); + return Ok(()); + } + + let mut rng = thread_rng(); + + loop { + // Generate random lines + let animal = animal_lines.choose(&mut rng).unwrap(); + let adjective = adj_lines.choose(&mut rng).unwrap().to_title_case(); + + // Check if the first character of adjective and animal match + if animal.chars().next() == adjective.chars().next() { + // Print the matched version name + println!("Your new Version Name:\n{} {}", adjective, animal); + break; + } + } + + Ok(()) }