Skip to content

Commit deeefcf

Browse files
authored
Merge pull request #1913 from mo8it/which
Use `which` instead of running `rustc --version`
2 parents 87ca05b + 8e0f7e5 commit deeefcf

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
@@ -18,6 +18,7 @@ regex = "1.10.3"
1818
serde_json = "1.0.114"
1919
serde = { version = "1.0.197", features = ["derive"] }
2020
toml = "0.8.10"
21+
which = "6.0.1"
2122

2223
[[bin]]
2324
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.");
@@ -399,18 +399,6 @@ fn watch(
399399
}
400400
}
401401

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

0 commit comments

Comments
 (0)