Skip to content

Commit 51b4c24

Browse files
committed
Use which instead of running rustc --version
1 parent 9c6f56b commit 51b4c24

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

Cargo.lock

Lines changed: 54 additions & 0 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ regex = "1.10.3"
1919
serde_json = "1.0.114"
2020
serde = { version = "1.0.197", features = ["derive"] }
2121
toml = "0.8.10"
22+
which = "6.0.1"
2223

2324
[[bin]]
2425
name = "rustlings"

src/main.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::ffi::OsStr;
1010
use std::fs;
1111
use std::io::{self, prelude::*};
1212
use std::path::Path;
13-
use std::process::{Command, Stdio};
13+
use std::process::Command;
1414
use std::sync::atomic::{AtomicBool, Ordering};
1515
use std::sync::mpsc::{channel, RecvTimeoutError};
1616
use std::sync::{Arc, Mutex};
@@ -100,7 +100,7 @@ fn main() {
100100
std::process::exit(1);
101101
}
102102

103-
if !rustc_exists() {
103+
if which::which("rustc").is_err() {
104104
println!("We cannot find `rustc`.");
105105
println!("Try running `rustc --version` to diagnose your problem.");
106106
println!("For instructions on how to install Rust, check the README.");
@@ -403,18 +403,6 @@ fn watch(
403403
}
404404
}
405405

406-
fn rustc_exists() -> bool {
407-
Command::new("rustc")
408-
.args(["--version"])
409-
.stdout(Stdio::null())
410-
.stderr(Stdio::null())
411-
.stdin(Stdio::null())
412-
.spawn()
413-
.and_then(|mut child| child.wait())
414-
.map(|status| status.success())
415-
.unwrap_or(false)
416-
}
417-
418406
const DEFAULT_OUT: &str = r#"Thanks for installing Rustlings!
419407
420408
Is this your first time? Don't worry, Rustlings was made for beginners! We are

0 commit comments

Comments
 (0)