Skip to content

Commit 7428386

Browse files
committed
refactor(fmt): Pull out stream lookup from write
1 parent e8674a2 commit 7428386

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/fmt/writer/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,20 @@ impl WritableTarget {
6767
let buf = buf.as_bytes();
6868
match self {
6969
WritableTarget::WriteStdout => {
70-
write!(std::io::stdout(), "{}", String::from_utf8_lossy(buf))?
70+
let mut stream = std::io::stdout().lock();
71+
write!(stream, "{}", String::from_utf8_lossy(buf))?;
7172
}
7273
WritableTarget::PrintStdout => print!("{}", String::from_utf8_lossy(buf)),
7374
WritableTarget::WriteStderr => {
74-
write!(std::io::stderr(), "{}", String::from_utf8_lossy(buf))?
75+
let mut stream = std::io::stderr().lock();
76+
write!(stream, "{}", String::from_utf8_lossy(buf))?;
7577
}
7678
WritableTarget::PrintStderr => eprint!("{}", String::from_utf8_lossy(buf)),
7779
// Safety: If the target type is `Pipe`, `target_pipe` will always be non-empty.
78-
WritableTarget::Pipe(pipe) => pipe.lock().unwrap().write_all(buf)?,
80+
WritableTarget::Pipe(pipe) => {
81+
let mut stream = pipe.lock().unwrap();
82+
write!(stream, "{}", String::from_utf8_lossy(buf))?;
83+
}
7984
}
8085

8186
Ok(())

0 commit comments

Comments
 (0)