Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Debug for public types #83 #105

Merged
merged 3 commits into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/bufreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::io;
use std::io::prelude::*;
use std::mem;

#[derive(Debug)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this type actually have a custom debug impl like BufReader in the standard library? That way we can avoid accidentally dumping out kilobytes of raw data :)

pub struct BufReader<R> {
inner: R,
buf: Box<[u8]>,
Expand Down
2 changes: 2 additions & 0 deletions src/crc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ use libc;
use ffi;

/// The CRC calculated by a CrcReader.
#[derive(Debug)]
pub struct Crc {
crc: libc::c_ulong,
amt: u32,
}

/// A wrapper around a `std::io::Read` that calculates the CRC.
#[derive(Debug)]
pub struct CrcReader<R> {
inner: R,
crc: Crc,
Expand Down
6 changes: 6 additions & 0 deletions src/deflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use {Compress, Decompress};
///
/// This structure implements a `Write` interface and takes a stream of
/// uncompressed data, writing the compressed data to the wrapped writer.
#[derive(Debug)]
pub struct EncoderWriter<W: Write> {
inner: zio::Writer<W, Compress>,
}
Expand All @@ -25,6 +26,7 @@ pub struct EncoderWriter<W: Write> {
///
/// This structure implements a `Read` interface and will read uncompressed
/// data from an underlying stream and emit a stream of compressed data.
#[derive(Debug)]
pub struct EncoderReader<R: Read> {
inner: EncoderReaderBuf<BufReader<R>>,
}
Expand All @@ -33,6 +35,7 @@ pub struct EncoderReader<R: Read> {
///
/// This structure implements a `BufRead` interface and will read uncompressed
/// data from an underlying stream and emit a stream of compressed data.
#[derive(Debug)]
pub struct EncoderReaderBuf<R: BufRead> {
obj: R,
data: Compress,
Expand All @@ -42,6 +45,7 @@ pub struct EncoderReaderBuf<R: BufRead> {
///
/// This structure implements a `Read` interface and takes a stream of
/// compressed data as input, providing the decompressed data when read from.
#[derive(Debug)]
pub struct DecoderReader<R: Read> {
inner: DecoderReaderBuf<BufReader<R>>,
}
Expand All @@ -50,6 +54,7 @@ pub struct DecoderReader<R: Read> {
///
/// This structure implements a `BufRead` interface and takes a stream of
/// compressed data as input, providing the decompressed data when read from.
#[derive(Debug)]
pub struct DecoderReaderBuf<R: BufRead> {
obj: R,
data: Decompress,
Expand All @@ -59,6 +64,7 @@ pub struct DecoderReaderBuf<R: BufRead> {
///
/// This structure implements a `Write` and will emit a stream of decompressed
/// data when fed a stream of compressed data.
#[derive(Debug)]
pub struct DecoderWriter<W: Write> {
inner: zio::Writer<W, Decompress>,
}
Expand Down
7 changes: 7 additions & 0 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ mod imp {
mem::size_of::<mz_stream>() as c_int)
}

#[derive(Debug)]
pub struct StreamWrapper{
inner: Box<mz_stream>,
}
Expand Down Expand Up @@ -105,6 +106,12 @@ mod imp {
inner: mz_stream,
}

impl ::std::fmt::Debug for StreamWrapper{
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error>{
write!(f, "StreamWrapper")
}
}

impl Default for StreamWrapper {
fn default() -> StreamWrapper {
StreamWrapper {
Expand Down
10 changes: 9 additions & 1 deletion src/gz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static FCOMMENT: u8 = 1 << 4;
///
/// This structure exposes a `Write` interface that will emit compressed data
/// to the underlying writer `W`.
#[derive(Debug)]
pub struct EncoderWriter<W: Write> {
inner: zio::Writer<W, Compress>,
crc: Crc,
Expand All @@ -41,6 +42,7 @@ pub struct EncoderWriter<W: Write> {
/// This structure exposes a `Read` interface that will read uncompressed data
/// from the underlying reader and expose the compressed version as a `Read`
/// interface.
#[derive(Debug)]
pub struct EncoderReader<R: Read> {
inner: EncoderReaderBuf<BufReader<R>>,
}
Expand All @@ -50,6 +52,7 @@ pub struct EncoderReader<R: Read> {
/// This structure exposes a `Read` interface that will read uncompressed data
/// from the underlying reader and expose the compressed version as a `Read`
/// interface.
#[derive(Debug)]
pub struct EncoderReaderBuf<R: BufRead> {
inner: deflate::EncoderReaderBuf<CrcReader<R>>,
header: Vec<u8>,
Expand All @@ -60,6 +63,7 @@ pub struct EncoderReaderBuf<R: BufRead> {
/// A builder structure to create a new gzip Encoder.
///
/// This structure controls header configuration options such as the filename.
#[derive(Debug)]
pub struct Builder {
extra: Option<Vec<u8>>,
filename: Option<CString>,
Expand All @@ -71,6 +75,7 @@ pub struct Builder {
///
/// This structure exposes a `Read` interface that will consume compressed
/// data from the underlying reader and emit uncompressed data.
#[derive(Debug)]
pub struct DecoderReader<R: Read> {
inner: DecoderReaderBuf<BufReader<R>>,
}
Expand All @@ -86,6 +91,7 @@ pub struct DecoderReader<R: Read> {
///
/// This structure exposes a `Read` interface that will consume all gzip members
/// from the underlying reader and emit uncompressed data.
#[derive(Debug)]
pub struct MultiDecoderReader<R: Read> {
inner: MultiDecoderReaderBuf<BufReader<R>>,
}
Expand All @@ -94,6 +100,7 @@ pub struct MultiDecoderReader<R: Read> {
///
/// This structure exposes a `Read` interface that will consume compressed
/// data from the underlying reader and emit uncompressed data.
#[derive(Debug)]
pub struct DecoderReaderBuf<R: BufRead> {
inner: CrcReader<deflate::DecoderReaderBuf<R>>,
header: Header,
Expand All @@ -111,6 +118,7 @@ pub struct DecoderReaderBuf<R: BufRead> {
///
/// This structure exposes a `Read` interface that will consume all gzip members
/// from the underlying reader and emit uncompressed data.
#[derive(Debug)]
pub struct MultiDecoderReaderBuf<R: BufRead> {
inner: CrcReader<deflate::DecoderReaderBuf<R>>,
header: Header,
Expand All @@ -121,7 +129,7 @@ pub struct MultiDecoderReaderBuf<R: BufRead> {
///
/// The header can contain metadata about the file that was compressed, if
/// present.
#[derive(PartialEq)]
#[derive(PartialEq, Debug)]
pub struct Header {
extra: Option<Vec<u8>>,
filename: Option<Vec<u8>>,
Expand Down
9 changes: 7 additions & 2 deletions src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use ffi;
///
/// It is recommended to use the I/O stream adaptors over this type as they're
/// easier to use.
#[derive(Debug)]
pub struct Compress {
inner: Stream<DirCompress>,
}
Expand All @@ -31,10 +32,12 @@ pub struct Compress {
///
/// It is recommended to use the I/O stream adaptors over this type as they're
/// easier to use.
#[derive(Debug)]
pub struct Decompress {
inner: Stream<DirDecompress>,
}

#[derive(Debug)]
struct Stream<D: Direction> {
stream_wrapper: ffi::StreamWrapper,
total_in: u64,
Expand All @@ -49,12 +52,14 @@ trait Direction {
unsafe fn destroy(stream: *mut ffi::mz_stream) -> c_int;
}

#[derive(Debug)]
enum DirCompress {}
#[derive(Debug)]
enum DirDecompress {}

/// Values which indicate the form of flushing to be used when compressing or
/// decompressing in-memory data.
#[derive(Copy, Clone, PartialEq, Eq)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Flush {
/// A typical parameter for passing to compression/decompression functions,
/// this indicates that the underlying stream to decide how much data to
Expand Down Expand Up @@ -113,7 +118,7 @@ pub struct DataError(());

/// Possible status results of compressing some data or successfully
/// decompressing a block of data.
#[derive(Copy, Clone, PartialEq, Eq)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Status {
/// Indicates success.
///
Expand Down
1 change: 1 addition & 0 deletions src/zio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::mem;

use {Decompress, Compress, Status, Flush, DataError};

#[derive(Debug)]
pub struct Writer<W: Write, D: Ops> {
obj: Option<W>,
pub data: D,
Expand Down
6 changes: 6 additions & 0 deletions src/zlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use {Compress, Decompress};
///
/// This structure implements a `Write` interface and takes a stream of
/// uncompressed data, writing the compressed data to the wrapped writer.
#[derive(Debug)]
pub struct EncoderWriter<W: Write> {
inner: zio::Writer<W, Compress>,
}
Expand All @@ -25,6 +26,7 @@ pub struct EncoderWriter<W: Write> {
///
/// This structure implements a `Read` interface and will read uncompressed
/// data from an underlying stream and emit a stream of compressed data.
#[derive(Debug)]
pub struct EncoderReader<R> {
inner: EncoderReaderBuf<BufReader<R>>,
}
Expand All @@ -33,6 +35,7 @@ pub struct EncoderReader<R> {
///
/// This structure implements a `BufRead` interface and will read uncompressed
/// data from an underlying stream and emit a stream of compressed data.
#[derive(Debug)]
pub struct EncoderReaderBuf<R> {
obj: R,
data: Compress,
Expand All @@ -42,6 +45,7 @@ pub struct EncoderReaderBuf<R> {
///
/// This structure implements a `Read` interface and takes a stream of
/// compressed data as input, providing the decompressed data when read from.
#[derive(Debug)]
pub struct DecoderReader<R> {
inner: DecoderReaderBuf<BufReader<R>>,
}
Expand All @@ -50,6 +54,7 @@ pub struct DecoderReader<R> {
///
/// This structure implements a `BufRead` interface and takes a stream of
/// compressed data as input, providing the decompressed data when read from.
#[derive(Debug)]
pub struct DecoderReaderBuf<R> {
obj: R,
data: Decompress,
Expand All @@ -59,6 +64,7 @@ pub struct DecoderReaderBuf<R> {
///
/// This structure implements a `Write` and will emit a stream of decompressed
/// data when fed a stream of compressed data.
#[derive(Debug)]
pub struct DecoderWriter<W: Write> {
inner: zio::Writer<W, Decompress>,
}
Expand Down