Skip to content

Commit

Permalink
chore(fmt): Add debug impls
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jan 18, 2024
1 parent 730b0a0 commit ea46409
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ impl Write for Formatter {

impl fmt::Debug for Formatter {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Formatter").finish()
let buf = self.buf.borrow();
f.debug_struct("Formatter")
.field("buf", &buf)
.field("write_style", &self.write_style)
.finish()
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/fmt/writer/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{io, sync::Mutex};

use crate::fmt::writer::WriteStyle;

#[derive(Debug)]
pub(in crate::fmt::writer) struct BufferWriter {
target: WritableTarget,
write_style: WriteStyle,
Expand Down Expand Up @@ -129,6 +130,12 @@ impl Buffer {
}
}

impl std::fmt::Debug for Buffer {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
String::from_utf8_lossy(self.as_bytes()).fmt(f)
}
}

/// Log target, either `stdout`, `stderr` or a custom pipe.
///
/// Same as `Target`, except the pipe is wrapped in a mutex for interior mutability.
Expand Down
9 changes: 2 additions & 7 deletions src/fmt/writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod buffer;
mod target;

use self::buffer::BufferWriter;
use std::{fmt, io, mem, sync::Mutex};
use std::{io, mem, sync::Mutex};

pub(super) use self::buffer::Buffer;

Expand Down Expand Up @@ -44,6 +44,7 @@ impl From<WriteStyle> for anstream::ColorChoice {
}

/// A terminal target with color awareness.
#[derive(Debug)]
pub(crate) struct Writer {
inner: BufferWriter,
}
Expand All @@ -62,12 +63,6 @@ impl Writer {
}
}

impl fmt::Debug for Writer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Writer").finish()
}
}

/// A builder for a terminal writer.
///
/// The target and style choice can be configured before building.
Expand Down

0 comments on commit ea46409

Please sign in to comment.