Skip to content

Commit d756c7a

Browse files
committed
tee: merge flush into write for simplicity
1 parent 5316f58 commit d756c7a

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

src/uu/tee/src/tee.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,16 @@ impl MultiWriter {
197197

198198
fn write_flush(&mut self, buf: &[u8]) -> Result<()> {
199199
let mode = self.output_error_mode;
200-
self.writers.retain_mut(|writer| {
201-
let res = (|| {
202-
writer.inner.write_all(buf)?;
203-
writer.inner.flush()
204-
})();
205-
match res {
200+
self.writers
201+
.retain_mut(|writer| match writer.inner.write_flush_all(buf) {
206202
Ok(()) => true,
207203
Err(e) => {
208204
if let Err(e) = process_error(mode, e, writer, &mut self.ignored_errors) {
209205
self.aborted.get_or_insert(e);
210206
}
211207
false
212208
}
213-
}
214-
});
209+
});
215210
self.aborted.take().map_or(
216211
if self.writers.is_empty() {
217212
// This error kind will never be raised by the standard
@@ -254,18 +249,17 @@ enum Writer {
254249
Stdout(std::io::Stdout),
255250
}
256251

257-
impl Write for Writer {
258-
fn write(&mut self, buf: &[u8]) -> Result<usize> {
252+
impl Writer {
253+
pub fn write_flush_all(&mut self, buf: &[u8]) -> Result<()> {
259254
match self {
260-
Self::File(f) => f.write(buf),
261-
Self::Stdout(s) => s.write(buf),
262-
}
263-
}
264-
265-
fn flush(&mut self) -> Result<()> {
266-
match self {
267-
Self::File(f) => f.flush(),
268-
Self::Stdout(s) => s.flush(),
255+
Self::File(f) => {
256+
f.write_all(buf)?;
257+
f.flush()
258+
}
259+
Self::Stdout(s) => {
260+
s.write_all(buf)?;
261+
s.flush()
262+
}
269263
}
270264
}
271265
}

0 commit comments

Comments
 (0)