Skip to content

Commit c8ff89a

Browse files
xtask: Remove generics from struct Io
Use `Box<dyn ...>` instead. No functional change, just reduces the need to add generic parameters outside of the `Io` implementation.
1 parent 3a70961 commit c8ff89a

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

xtask/src/pipe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Pipe {
6060
}
6161

6262
/// Create an `Io` object for performing reads and writes.
63-
pub fn open_io(&self) -> Result<Io<File, File>> {
63+
pub fn open_io(&self) -> Result<Io> {
6464
let reader;
6565
let writer;
6666

xtask/src/qemu.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,20 @@ fn add_pflash_args(cmd: &mut Command, file: &Path, mode: PflashMode) {
236236
cmd.arg(arg);
237237
}
238238

239-
pub struct Io<R: Read, W: Write> {
240-
reader: BufReader<R>,
241-
writer: W,
239+
pub struct Io {
240+
reader: BufReader<Box<dyn Read + Send>>,
241+
writer: Box<dyn Write + Send>,
242242
}
243243

244-
impl<R: Read, W: Write> Io<R, W> {
245-
pub fn new(r: R, w: W) -> Self {
244+
impl Io {
245+
pub fn new<R, W>(r: R, w: W) -> Self
246+
where
247+
R: Read + Send + 'static,
248+
W: Write + Send + 'static,
249+
{
246250
Self {
247-
reader: BufReader::new(r),
248-
writer: w,
251+
reader: BufReader::new(Box::new(r)),
252+
writer: Box::new(w),
249253
}
250254
}
251255

@@ -277,7 +281,7 @@ impl<R: Read, W: Write> Io<R, W> {
277281
}
278282
}
279283

280-
fn echo_filtered_stdout<R: Read, W: Write>(mut child_io: Io<R, W>) {
284+
fn echo_filtered_stdout(mut child_io: Io) {
281285
// This regex is used to detect and strip ANSI escape codes. These
282286
// escapes are added by the console output protocol when writing to
283287
// the serial device.
@@ -293,11 +297,7 @@ fn echo_filtered_stdout<R: Read, W: Write>(mut child_io: Io<R, W>) {
293297
}
294298
}
295299

296-
fn process_qemu_io<R: Read, W: Write>(
297-
mut monitor_io: Io<R, W>,
298-
mut serial_io: Io<R, W>,
299-
tmp_dir: &Path,
300-
) -> Result<()> {
300+
fn process_qemu_io(mut monitor_io: Io, mut serial_io: Io, tmp_dir: &Path) -> Result<()> {
301301
// Execute the QEMU monitor handshake, doing basic sanity checks.
302302
assert!(monitor_io.read_line()?.starts_with(r#"{"QMP":"#));
303303
monitor_io.write_json(json!({"execute": "qmp_capabilities"}))?;

0 commit comments

Comments
 (0)