mirror of
https://github.com/notohh/rustlings.git
synced 2024-10-30 16:59:12 -04:00
Use the NotFound variant of the IO error
This commit is contained in:
parent
83cd91ccca
commit
e4520602f5
1 changed files with 9 additions and 10 deletions
19
src/main.rs
19
src/main.rs
|
@ -91,15 +91,6 @@ fn main() {
|
|||
println!("\n{WELCOME}\n");
|
||||
}
|
||||
|
||||
if !Path::new("info.toml").exists() {
|
||||
println!(
|
||||
"{} must be run from the rustlings directory",
|
||||
std::env::current_exe().unwrap().to_str().unwrap()
|
||||
);
|
||||
println!("Try `cd rustlings/`!");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
if !rustc_exists() {
|
||||
println!("We cannot find `rustc`.");
|
||||
println!("Try running `rustc --version` to diagnose your problem.");
|
||||
|
@ -107,7 +98,15 @@ fn main() {
|
|||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let info_file = fs::read_to_string("info.toml").unwrap();
|
||||
let info_file = fs::read_to_string("info.toml").unwrap_or_else(|e| {
|
||||
match e.kind() {
|
||||
io::ErrorKind::NotFound => println!(
|
||||
"The program must be run from the rustlings directory\nTry `cd rustlings/`!",
|
||||
),
|
||||
_ => println!("Failed to read the info.toml file: {e}"),
|
||||
}
|
||||
std::process::exit(1);
|
||||
});
|
||||
let exercises = toml_edit::de::from_str::<ExerciseList>(&info_file)
|
||||
.unwrap()
|
||||
.exercises;
|
||||
|
|
Loading…
Reference in a new issue