Skip to content

Commit 9fcb23f

Browse files
committed
Simplify process access to stdout
1 parent d63ef9f commit 9fcb23f

File tree

8 files changed

+14
-34
lines changed

8 files changed

+14
-34
lines changed

src/cli/common.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ use once_cell::sync::Lazy;
1414

1515
use super::self_update;
1616
use crate::cli::download_tracker::DownloadTracker;
17-
use crate::currentprocess::{
18-
filesource::{StdinSource, StdoutSource},
19-
terminalsource,
20-
varsource::VarSource,
21-
};
17+
use crate::currentprocess::{filesource::StdinSource, terminalsource, varsource::VarSource};
2218
use crate::dist::dist::{TargetTriple, ToolchainDesc};
2319
use crate::install::UpdateStatus;
2420
use crate::utils::notifications as util_notifications;

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::utils::units::{Size, Unit, UnitMode};
1010
use crate::utils::Notification as Un;

src/cli/rustup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::{
2020
topical_doc,
2121
},
2222
command,
23-
currentprocess::filesource::{StderrSource, StdoutSource},
23+
currentprocess::filesource::StderrSource,
2424
dist::{
2525
dist::{PartialToolchainDesc, Profile, TargetTriple},
2626
manifest::{Component, ComponentStatus},

src/cli/self_update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use crate::{
6565
errors::*,
6666
markdown::md,
6767
},
68-
currentprocess::{filesource::StdoutSource, varsource::VarSource},
68+
currentprocess::varsource::VarSource,
6969
dist::dist::{self, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc},
7070
install::UpdateStatus,
7171
process,

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, varsource::VarSource};
15+
use crate::currentprocess::varsource::VarSource;
1616
use crate::dist::dist::TargetTriple;
1717
use crate::process;
1818
use crate::utils::utils;

src/cli/setup_mode.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::{
66
common,
77
self_update::{self, InstallOpts},
88
},
9-
currentprocess::filesource::StdoutSource,
109
dist::dist::Profile,
1110
process,
1211
toolchain::names::MaybeOfficialToolchainName,

src/currentprocess.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ pub trait CurrentProcess:
6868
home::Env
6969
+ CurrentDirSource
7070
+ VarSource
71-
+ StdoutSource
7271
+ StderrSource
7372
+ StdinSource
7473
+ ProcessSource
@@ -82,7 +81,6 @@ pub trait CurrentProcess:
8281
CurrentProcess,
8382
CurrentDirSource,
8483
VarSource,
85-
StdoutSource,
8684
StderrSource,
8785
StdinSource,
8886
ProcessSource
@@ -122,6 +120,14 @@ impl Process {
122120
Process::TestProcess(p) => Box::new(p.args.iter().map(OsString::from)),
123121
}
124122
}
123+
124+
pub(crate) fn stdout(&self) -> Box<dyn filesource::Writer> {
125+
match self {
126+
Process::OSProcess(_) => Box::new(io::stdout()),
127+
#[cfg(feature = "test")]
128+
Process::TestProcess(p) => Box::new(filesource::TestWriter(p.stdout.clone())),
129+
}
130+
}
125131
}
126132

127133
/// Obtain the current instance of CurrentProcess

src/currentprocess/filesource.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ pub trait Writer: Write + Send + Sync {
107107
fn terminal(&self) -> ColorableTerminal;
108108
}
109109

110-
// -------------- stdout -------------------------------
111-
112-
/// Stand-in for [`std::io::stdout`].
113-
#[enum_dispatch]
114-
pub trait StdoutSource {
115-
fn stdout(&self) -> Box<dyn Writer>;
116-
}
117-
118110
// -------------- stderr -------------------------------
119111

120112
/// Stand-in for std::io::stderr.
@@ -145,12 +137,6 @@ impl Writer for io::Stdout {
145137
}
146138
}
147139

148-
impl StdoutSource for super::OSProcess {
149-
fn stdout(&self) -> Box<dyn Writer> {
150-
Box::new(io::stdout())
151-
}
152-
}
153-
154140
impl WriterLock for io::StderrLock<'_> {}
155141

156142
impl Writer for io::Stderr {
@@ -200,7 +186,7 @@ pub(super) type TestWriterInner = Arc<Mutex<Vec<u8>>>;
200186
/// A thread-safe test file handle that pretends to be e.g. stdout.
201187
#[derive(Clone, Default)]
202188
#[cfg(feature = "test")]
203-
pub(super) struct TestWriter(TestWriterInner);
189+
pub(super) struct TestWriter(pub(super) TestWriterInner);
204190

205191
#[cfg(feature = "test")]
206192
impl TestWriter {
@@ -239,13 +225,6 @@ impl Write for TestWriter {
239225
}
240226
}
241227

242-
#[cfg(feature = "test")]
243-
impl StdoutSource for super::TestProcess {
244-
fn stdout(&self) -> Box<dyn Writer> {
245-
Box::new(TestWriter(self.stdout.clone()))
246-
}
247-
}
248-
249228
#[cfg(feature = "test")]
250229
impl StderrSource for super::TestProcess {
251230
fn stderr(&self) -> Box<dyn Writer> {

0 commit comments

Comments
 (0)