commit 7bdc3ecfb23e32dcc64c1532eb2564469934af99
parent e4b4eaeedf6fe783e583d36685943a00e8e1b340
Author: Yuval Langer <yuval.langer@gmail.com>
Date: Wed, 6 Nov 2024 20:44:17 +0200
Switch to non-fully-qualified names.
Convert from `std::io::IKnowExactlyWhereThisNameCameFrom` into
`WhoKnowsWhereThisNameCameFrom` because people who shall remain
unnamed find fully qualified names offensive and an eyesore.
Diffstat:
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/main.rs b/src/main.rs
@@ -19,9 +19,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
extern crate getopts;
extern crate rand;
+use std::env;
use std::fs::File;
-// use std::io::BufRead;
+use std::io::Bytes;
use std::io::Read;
+use std::io::Stdin;
+use std::io::stdin;
use std::process::exit;
use std::str::FromStr;
@@ -67,13 +70,13 @@ fn unknown_wordlist(wordlist_name: &str) -> ! {
}
struct ReadWordDieCasts<'a, T> {
- bytes_iter: &'a mut std::io::Bytes<T>,
+ bytes_iter: &'a mut Bytes<T>,
wordlist: &'a Vec<&'a str>,
}
impl<T> ReadWordDieCasts<'_, T> {
fn new<'a, D>(
- bytes_iter: &'a mut std::io::Bytes<T>,
+ bytes_iter: &'a mut Bytes<T>,
wordlist: &'a Vec<&'a str>,
) -> ReadWordDieCasts<'a, T> {
ReadWordDieCasts {
@@ -83,7 +86,7 @@ impl<T> ReadWordDieCasts<'_, T> {
}
}
-impl<T: std::io::Read> Iterator for ReadWordDieCasts<'_, T> {
+impl<T: Read> Iterator for ReadWordDieCasts<'_, T> {
type Item = String;
fn next(&mut self) -> Option<<ReadWordDieCasts<T> as Iterator>::Item> {
@@ -92,9 +95,9 @@ impl<T: std::io::Read> Iterator for ReadWordDieCasts<'_, T> {
}
fn read_single_word<T>(
- bytes_iter: &mut std::io::Bytes<T>,
+ bytes_iter: &mut Bytes<T>,
wordlist: &Vec<&str>,
-) -> Option<String> where T: std::io::Read {
+) -> Option<String> where T: Read {
let die_cast_per_word = die_cast_per_word(wordlist.len());
let mut word_index = 0;
@@ -234,7 +237,7 @@ fn die_cast_per_word(wordlist_length: usize) -> u32 {
}
fn main() {
- let args: Vec<String> = std::env::args().collect();
+ let args: Vec<String> = env::args().collect();
let program = &args[0];
let opts = make_options();
@@ -288,10 +291,10 @@ fn main() {
};
if is_physical_rolls {
- let stdin = std::io::stdin();
+ let stdin = stdin();
let mut bytes_iter = stdin.bytes();
- let mut words = ReadWordDieCasts::new::<std::io::Bytes<std::io::Stdin>>(&mut bytes_iter, &wordlist);
+ let mut words = ReadWordDieCasts::new::<Bytes<Stdin>>(&mut bytes_iter, &wordlist);
if let Some(word) = words.next() {
print!("{}", word);
@@ -334,13 +337,14 @@ fn main() {
#[cfg(test)]
mod tests {
+ use std::io::BufReader;
use super::*;
#[test]
fn test_read_single_word() {
let wordlist = Wordlist::default().get_list().to_vec();
let input = &b"11111\n"[..];
- let mut reader = std::io::BufReader::with_capacity(input.len(), input).bytes();
+ let mut reader = BufReader::with_capacity(input.len(), input).bytes();
assert_eq!("abacus", read_single_word(&mut reader, &wordlist).unwrap());
}