Skip to content

Commit 5230106

Browse files
committed
Simplify process access to stdout
1 parent c528452 commit 5230106

File tree

8 files changed

+15
-31
lines changed

8 files changed

+15
-31
lines changed

src/cli/common.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ use once_cell::sync::Lazy;
1515
use super::self_update;
1616
use crate::cli::download_tracker::DownloadTracker;
1717
use crate::currentprocess::{
18-
filesource::{StdinSource, StdoutSource},
19-
process, terminalsource,
20-
varsource::VarSource,
18+
filesource::StdinSource, process, terminalsource, varsource::VarSource,
2119
};
2220
use crate::dist::dist::{TargetTriple, ToolchainDesc};
2321
use crate::dist::manifest::ComponentStatus;

src/cli/download_tracker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::io::Write;
44
use std::sync::{Arc, Mutex};
55
use std::time::{Duration, Instant};
66

7-
use crate::currentprocess::{filesource::StdoutSource, process, terminalsource};
7+
use crate::currentprocess::{process, terminalsource};
88
use crate::dist::Notification as In;
99
use crate::notifications::Notification;
1010
use crate::utils::units::{Size, Unit, UnitMode};

src/cli/rustup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
command,
2525
config::{new_toolchain_with_reason, ActiveReason, Cfg},
2626
currentprocess::{
27-
filesource::{StderrSource, StdoutSource},
27+
filesource::StderrSource,
2828
process,
2929
terminalsource::{self, ColorableTerminal},
3030
},

src/cli/self_update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use crate::{
6666
markdown::md,
6767
},
6868
config::Cfg,
69-
currentprocess::{filesource::StdoutSource, process, varsource::VarSource},
69+
currentprocess::{process, varsource::VarSource},
7070
dist::dist::{self, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc},
7171
install::UpdateStatus,
7272
toolchain::{

src/cli/self_update/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::super::errors::*;
1212
use super::common;
1313
use super::{install_bins, InstallOpts};
1414
use crate::cli::download_tracker::DownloadTracker;
15-
use crate::currentprocess::{filesource::StdoutSource, process, varsource::VarSource};
15+
use crate::currentprocess::{process, varsource::VarSource};
1616
use crate::dist::dist::TargetTriple;
1717
use crate::utils::utils;
1818
use crate::utils::Notification;

src/cli/setup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
common,
77
self_update::{self, InstallOpts},
88
},
9-
currentprocess::{filesource::StdoutSource, process},
9+
currentprocess::process,
1010
dist::dist::Profile,
1111
toolchain::names::MaybeOfficialToolchainName,
1212
utils::utils,

src/currentprocess.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ pub trait CurrentProcess:
6969
home::Env
7070
+ CurrentDirSource
7171
+ VarSource
72-
+ StdoutSource
7372
+ StderrSource
7473
+ StdinSource
7574
+ ProcessSource
@@ -83,7 +82,6 @@ pub trait CurrentProcess:
8382
CurrentProcess,
8483
CurrentDirSource,
8584
VarSource,
86-
StdoutSource,
8785
StderrSource,
8886
StdinSource,
8987
ProcessSource
@@ -123,6 +121,14 @@ impl Process {
123121
Process::TestProcess(p) => Box::new(p.args.iter().map(OsString::from)),
124122
}
125123
}
124+
125+
pub(crate) fn stdout(&self) -> Box<dyn filesource::Writer> {
126+
match self {
127+
Process::OSProcess(_) => Box::new(io::stdout()),
128+
#[cfg(feature = "test")]
129+
Process::TestProcess(p) => Box::new(filesource::TestWriter(p.stdout.clone())),
130+
}
131+
}
126132
}
127133

128134
/// Obtain the current instance of CurrentProcess

src/currentprocess/filesource.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ pub trait Writer: Write + Send + Sync {
6060
fn terminal(&self) -> ColorableTerminal;
6161
}
6262

63-
// -------------- stdout -------------------------------
64-
65-
/// Stand-in for [`std::io::stdout`].
66-
#[enum_dispatch]
67-
pub trait StdoutSource {
68-
fn stdout(&self) -> Box<dyn Writer>;
69-
}
70-
7163
// -------------- stderr -------------------------------
7264

7365
/// Stand-in for std::io::stderr.
@@ -98,12 +90,6 @@ impl Writer for io::Stdout {
9890
}
9991
}
10092

101-
impl StdoutSource for super::OSProcess {
102-
fn stdout(&self) -> Box<dyn Writer> {
103-
Box::new(io::stdout())
104-
}
105-
}
106-
10793
impl WriterLock for io::StderrLock<'_> {}
10894

10995
impl Writer for io::Stderr {
@@ -208,7 +194,7 @@ mod test_support {
208194

209195
/// A thread-safe test file handle that pretends to be e.g. stdout.
210196
#[derive(Clone, Default)]
211-
pub(in super::super) struct TestWriter(TestWriterInner);
197+
pub(in super::super) struct TestWriter(pub(in super::super) TestWriterInner);
212198

213199
impl TestWriter {
214200
pub(in super::super) fn lock(&self) -> TestWriterLock<'_> {
@@ -244,12 +230,6 @@ mod test_support {
244230
}
245231
}
246232

247-
impl StdoutSource for TestProcess {
248-
fn stdout(&self) -> Box<dyn Writer> {
249-
Box::new(TestWriter(self.stdout.clone()))
250-
}
251-
}
252-
253233
impl StderrSource for TestProcess {
254234
fn stderr(&self) -> Box<dyn Writer> {
255235
Box::new(TestWriter(self.stderr.clone()))

0 commit comments

Comments
 (0)