1 use std
::{io, sync::Mutex}
;
3 use crate::fmt
::{WritableTarget, WriteStyle}
;
5 pub(in crate::fmt
::writer
) mod glob {}
7 pub(in crate::fmt
::writer
) struct BufferWriter
{
8 target
: WritableTarget
,
11 pub(in crate::fmt
) struct Buffer(Vec
<u8>);
14 pub(in crate::fmt
::writer
) fn stderr(_is_test
: bool
, _write_style
: WriteStyle
) -> Self {
16 target
: WritableTarget
::Stderr
,
20 pub(in crate::fmt
::writer
) fn stdout(_is_test
: bool
, _write_style
: WriteStyle
) -> Self {
22 target
: WritableTarget
::Stdout
,
26 pub(in crate::fmt
::writer
) fn pipe(
27 _write_style
: WriteStyle
,
28 pipe
: Box
<Mutex
<dyn io
::Write
+ Send
+ '
static>>,
31 target
: WritableTarget
::Pipe(pipe
),
35 pub(in crate::fmt
::writer
) fn buffer(&self) -> Buffer
{
39 pub(in crate::fmt
::writer
) fn print(&self, buf
: &Buffer
) -> io
::Result
<()> {
40 // This impl uses the `eprint` and `print` macros
41 // instead of using the streams directly.
42 // This is so their output can be captured by `cargo test`.
44 // Safety: If the target type is `Pipe`, `target_pipe` will always be non-empty.
45 WritableTarget
::Pipe(pipe
) => pipe
.lock().unwrap().write_all(&buf
.0)?
,
46 WritableTarget
::Stdout
=> print
!("{}", String
::from_utf8_lossy(&buf
.0)),
47 WritableTarget
::Stderr
=> eprint
!("{}", String
::from_utf8_lossy(&buf
.0)),
55 pub(in crate::fmt
) fn clear(&mut self) {
59 pub(in crate::fmt
) fn write(&mut self, buf
: &[u8]) -> io
::Result
<usize> {
64 pub(in crate::fmt
) fn flush(&mut self) -> io
::Result
<()> {
69 pub(in crate::fmt
) fn bytes(&self) -> &[u8] {