Skip to content

Commit b8a5886

Browse files
authored
Merge pull request #1914 from mo8it/toml
Reading the `info.toml` file
2 parents 07dec76 + b9d2756 commit b8a5886

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

Cargo.lock

Lines changed: 12 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ notify-debouncer-mini = "0.4.1"
1717
regex = "1.10.3"
1818
serde_json = "1.0.114"
1919
serde = { version = "1.0.197", features = ["derive"] }
20-
toml = "0.8.10"
20+
toml_edit = { version = "0.22.9", default-features = false, features = ["parse", "serde"] }
2121
which = "6.0.1"
2222

2323
[[bin]]

src/main.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,25 @@ fn main() {
9191
println!("\n{WELCOME}\n");
9292
}
9393

94-
if !Path::new("info.toml").exists() {
95-
println!(
96-
"{} must be run from the rustlings directory",
97-
std::env::current_exe().unwrap().to_str().unwrap()
98-
);
99-
println!("Try `cd rustlings/`!");
100-
std::process::exit(1);
101-
}
102-
10394
if which::which("rustc").is_err() {
10495
println!("We cannot find `rustc`.");
10596
println!("Try running `rustc --version` to diagnose your problem.");
10697
println!("For instructions on how to install Rust, check the README.");
10798
std::process::exit(1);
10899
}
109100

110-
let toml_str = &fs::read_to_string("info.toml").unwrap();
111-
let exercises = toml::from_str::<ExerciseList>(toml_str).unwrap().exercises;
101+
let info_file = fs::read_to_string("info.toml").unwrap_or_else(|e| {
102+
match e.kind() {
103+
io::ErrorKind::NotFound => println!(
104+
"The program must be run from the rustlings directory\nTry `cd rustlings/`!",
105+
),
106+
_ => println!("Failed to read the info.toml file: {e}"),
107+
}
108+
std::process::exit(1);
109+
});
110+
let exercises = toml_edit::de::from_str::<ExerciseList>(&info_file)
111+
.unwrap()
112+
.exercises;
112113
let verbose = args.nocapture;
113114

114115
let command = args.command.unwrap_or_else(|| {

0 commit comments

Comments
 (0)