Skip to content

Commit 59d15e6

Browse files
committed
Remove unnecessary trait abstraction
1 parent 6b2508e commit 59d15e6

File tree

4 files changed

+14
-57
lines changed

4 files changed

+14
-57
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ clap_complete = "4"
5050
download = { path = "download", default-features = false }
5151
effective-limits = "0.5.5"
5252
enum-map = "2.5.0"
53-
enum_dispatch.workspace = true
5453
flate2 = "1"
5554
fs_at.workspace = true
5655
git-testament = "0.2"
@@ -134,7 +133,6 @@ members = ["download", "rustup-macros"]
134133

135134
[workspace.dependencies]
136135
anyhow = "1.0.69"
137-
enum_dispatch = "0.3.11"
138136
fs_at = "0.1.6"
139137
once_cell = "1.18.0"
140138
opentelemetry = "0.23"

src/bin/rustup-init.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustup::cli::rustup_mode;
2727
#[cfg(windows)]
2828
use rustup::cli::self_update;
2929
use rustup::cli::setup_mode;
30-
use rustup::currentprocess::{process, with_runtime, OSProcess};
30+
use rustup::currentprocess::{process, with_runtime, Process};
3131
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
3232
use rustup::is_proxyable_tools;
3333
use rustup::utils::utils::{self, ExitCode};
@@ -36,10 +36,10 @@ fn main() {
3636
#[cfg(windows)]
3737
pre_rustup_main_init();
3838

39-
let process = OSProcess::default();
39+
let process = Process::os();
4040
let mut builder = Builder::new_multi_thread();
4141
builder.enable_all();
42-
with_runtime(process.into(), builder, {
42+
with_runtime(process, builder, {
4343
async {
4444
match maybe_trace_rustup().await {
4545
Err(e) => {

src/currentprocess.rs

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,60 +15,25 @@ use std::{
1515
sync::{Arc, Mutex},
1616
};
1717

18-
use enum_dispatch::enum_dispatch;
1918
#[cfg(feature = "test")]
2019
use rand::{thread_rng, Rng};
2120

2221
pub mod filesource;
2322
pub mod terminalsource;
2423

25-
/// An abstraction for the current process.
26-
///
27-
/// This acts as a clonable proxy to the global state provided by some key OS
28-
/// interfaces - it is a zero cost abstraction. For the test variant it manages
29-
/// a mutex and takes out locks to ensure consistency.
30-
///
31-
/// This provides replacements env::arg*, env::var*, and the standard files
32-
/// io::std* with traits that are customisable for tests. As a result any macros
33-
/// or code that have non-pluggable usage of those are incompatible with
34-
/// CurrentProcess and must not be used. That includes \[e\]println! as well as
35-
/// third party crates.
36-
///
37-
/// CurrentProcess is used via an instance in a thread local variable; when
38-
/// making new threads, be sure to copy CurrentProcess::process() into the new
39-
/// thread before calling any code that may need to use a CurrentProcess
40-
/// function.
41-
///
42-
/// Run some code using with: this will set the current instance, call your
43-
/// function, then finally reset the instance at the end before returning.
44-
///
45-
/// Testing level interoperation with external code that depends on environment
46-
/// variables could be possible with a hypothetical `with_projected()` which
47-
/// would be a zero-cost operation in real processes, but in test processes will
48-
/// take a lock out to mutually exclude other code, then overwrite the current
49-
/// value of std::env::vars, restoring it at the end. However, the only use for
50-
/// that today is a test of cargo::home, which is now implemented in a separate
51-
/// crate, so we've just deleted the test.
52-
///
53-
/// A thread local is used to permit the instance to be available to the entire
54-
/// rustup library without needing to explicitly wire this normally global state
55-
/// everywhere; and a trait object with dyn dispatch is likewise used to avoid
56-
/// needing to thread trait parameters across the entire code base: none of the
57-
/// methods are in performance critical loops (except perhaps progress bars -
58-
/// and even there we should be doing debouncing and managing update rates).
59-
#[enum_dispatch]
60-
pub trait CurrentProcess: Debug {}
61-
6224
/// Allows concrete types for the currentprocess abstraction.
6325
#[derive(Clone, Debug)]
64-
#[enum_dispatch(CurrentProcess)]
6526
pub enum Process {
6627
OSProcess(OSProcess),
6728
#[cfg(feature = "test")]
6829
TestProcess(TestProcess),
6930
}
7031

7132
impl Process {
33+
pub fn os() -> Self {
34+
Self::OSProcess(OSProcess::new())
35+
}
36+
7237
pub fn name(&self) -> Option<String> {
7338
let arg0 = match self.var("RUSTUP_FORCE_ARG0") {
7439
Ok(v) => Some(v),
@@ -185,6 +150,13 @@ impl home::env::Env for Process {
185150
}
186151
}
187152

153+
#[cfg(feature = "test")]
154+
impl From<TestProcess> for Process {
155+
fn from(p: TestProcess) -> Self {
156+
Self::TestProcess(p)
157+
}
158+
}
159+
188160
/// Obtain the current instance of CurrentProcess
189161
pub fn process() -> Process {
190162
home_process()

0 commit comments

Comments
 (0)