Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/uu/tee/src/tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,22 @@ enum Writer {
Stdout(std::io::Stdout),
}

// todo: move this to uucore and remove Box dyn from many utils
macro_rules! dispatch {
($self:ident, $method:ident $(, $arg:expr)*) => {
match $self {
Writer::File(f) => f.$method($($arg),*),
Writer::Stdout(s) => s.$method($($arg),*),
}
};
}

impl Write for Writer {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
match self {
Self::File(f) => f.write(buf),
Self::Stdout(s) => s.write(buf),
}
dispatch!(self, write, buf)
}

fn flush(&mut self) -> Result<()> {
match self {
Self::File(f) => f.flush(),
Self::Stdout(s) => s.flush(),
}
dispatch!(self, flush)
}
}

Expand Down
Loading