コンソールで動作します
データは↓にあります
drive.google.com
Cargo.toml
[dependencies] rand = "0.8"
main.rs
use std::fs::File; use std::io::{self,Write,BufRead}; use std::path::Path; use rand::seq::SliceRandom; use rand::thread_rng; fn main() -> io::Result<()> { let path = Path::new("高校英語.csv"); let file = File::open(&path)?; let reader = io::BufReader::new(file); let mut matrix: Vec<Vec<String>> = Vec::new(); for line in reader.lines() { let line = line?; let parts:Vec<&str>=line.split(',').collect(); matrix.push(vec![parts[0].to_string(),parts[1].to_string(),parts[2].to_string(),parts[3].to_string(),parts[4].to_string()]); } let rowmax=matrix.len(); matrix.shuffle(&mut thread_rng()); let mut row=0; loop{ if rowmax == row { println!("全て表示しました 終了します"); break; } let mut input = String::new(); println!("-------------------------------"); println!("Word:{}",matrix[row][2].to_string()); println!("-------------------------------"); print!("終了するには何らかの文字を入力:"); io::stdout().flush().unwrap(); io::stdin().read_line(&mut input).expect("Failed to read line"); if input.trim_end() != "" { println!("{}",input); println!("終了します"); break; } println!("Rank:{}",matrix[row][0].to_string()); println!("品詞:{}",matrix[row][1].to_string()); println!("発音:{}",matrix[row][3].to_string()); println!("意味:{}",matrix[row][4].to_string()); row+=1; } Ok(()) }