Skip to content

Commit

Permalink
Implement custom Debug trait for BufReader rust-lang#83
Browse files Browse the repository at this point in the history
  • Loading branch information
kper committed Apr 19, 2017
1 parent e3fd774 commit 6773395
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/bufreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ use std::io;
use std::io::prelude::*;
use std::mem;

#[derive(Debug)]
pub struct BufReader<R> {
inner: R,
buf: Box<[u8]>,
pos: usize,
cap: usize,
}

impl<R> ::std::fmt::Debug for BufReader<R> where R: ::std::fmt::Debug {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error>{
fmt.debug_struct("BufReader")
.field("reader", &self.inner)
.field("buffer", &format_args!("{}/{}", self.cap - self.pos, self.buf.len()))
.finish()
}
}

impl<R: Read> BufReader<R> {
pub fn new(inner: R) -> BufReader<R> {
BufReader::with_buf(vec![0; 32 * 1024], inner)
Expand Down

0 comments on commit 6773395

Please sign in to comment.