diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2020-11-02 10:24:25 +0100 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2020-11-09 13:06:59 +0100 |
commit | 8712c52b31b1ed16a1470adb46cf3f7fd7cc65e8 (patch) | |
tree | 8b9758728c041ea0e666d6c4b08d268415100e3b | |
parent | 41bcc909751d8f465e2c557276f53935d54e5e9c (diff) |
buffered-reader: Add Debug trait bound to Cookie.
-rw-r--r-- | buffered-reader/src/adapter.rs | 14 | ||||
-rw-r--r-- | buffered-reader/src/decompress_bzip2.rs | 12 | ||||
-rw-r--r-- | buffered-reader/src/decompress_deflate.rs | 24 | ||||
-rw-r--r-- | buffered-reader/src/dup.rs | 12 | ||||
-rw-r--r-- | buffered-reader/src/eof.rs | 2 | ||||
-rw-r--r-- | buffered-reader/src/file_generic.rs | 12 | ||||
-rw-r--r-- | buffered-reader/src/file_unix.rs | 20 | ||||
-rw-r--r-- | buffered-reader/src/generic.rs | 12 | ||||
-rw-r--r-- | buffered-reader/src/lib.rs | 12 | ||||
-rw-r--r-- | buffered-reader/src/limitor.rs | 12 | ||||
-rw-r--r-- | buffered-reader/src/memory.rs | 12 | ||||
-rw-r--r-- | buffered-reader/src/reserve.rs | 14 | ||||
-rw-r--r-- | openpgp/src/crypto/symmetric.rs | 12 | ||||
-rw-r--r-- | openpgp/src/parse.rs | 8 |
14 files changed, 90 insertions, 88 deletions
diff --git a/buffered-reader/src/adapter.rs b/buffered-reader/src/adapter.rs index 6dc081e0..cb19c3df 100644 --- a/buffered-reader/src/adapter.rs +++ b/buffered-reader/src/adapter.rs @@ -9,19 +9,19 @@ use super::*; /// Generic::with_cookie(b, _)`, but that introduces buffering. This /// `Adapter` also changes cookie types, but does no buffering of its /// own. -pub struct Adapter<T: BufferedReader<B>, B, C> { +pub struct Adapter<T: BufferedReader<B>, B: fmt::Debug, C: fmt::Debug> { reader: T, _ghostly_cookie: std::marker::PhantomData<B>, cookie: C, } -impl<T: BufferedReader<B>, B, C> fmt::Display for Adapter<T, B, C> { +impl<T: BufferedReader<B>, B: fmt::Debug, C: fmt::Debug> fmt::Display for Adapter<T, B, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Adapter") } } -impl<T: BufferedReader<B>, B, C> fmt::Debug for Adapter<T, B, C> { +impl<T: BufferedReader<B>, B: fmt::Debug, C: fmt::Debug> fmt::Debug for Adapter<T, B, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Adapter") .field("reader", &self.reader) @@ -29,7 +29,7 @@ impl<T: BufferedReader<B>, B, C> fmt::Debug for Adapter<T, B, C> { } } -impl<T: BufferedReader<B>, B> Adapter<T, B, ()> { +impl<T: BufferedReader<B>, B: fmt::Debug> Adapter<T, B, ()> { /// Instantiates a new adapter. /// /// `reader` is the source to wrap. @@ -38,7 +38,7 @@ impl<T: BufferedReader<B>, B> Adapter<T, B, ()> { } } -impl<T: BufferedReader<B>, B, C> Adapter<T, B, C> { +impl<T: BufferedReader<B>, B: fmt::Debug, C: fmt::Debug> Adapter<T, B, C> { /// Like `new()`, but sets a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -53,13 +53,13 @@ impl<T: BufferedReader<B>, B, C> Adapter<T, B, C> { } } -impl<T: BufferedReader<B>, B, C> io::Read for Adapter<T, B, C> { +impl<T: BufferedReader<B>, B: fmt::Debug, C: fmt::Debug> io::Read for Adapter<T, B, C> { fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> { self.reader.read(buf) } } -impl<T: BufferedReader<B>, B, C> BufferedReader<C> for Adapter<T, B, C> { +impl<T: BufferedReader<B>, B: fmt::Debug, C: fmt::Debug> BufferedReader<C> for Adapter<T, B, C> { fn buffer(&self) -> &[u8] { self.reader.buffer() } diff --git a/buffered-reader/src/decompress_bzip2.rs b/buffered-reader/src/decompress_bzip2.rs index ddb0dd67..12bd7246 100644 --- a/buffered-reader/src/decompress_bzip2.rs +++ b/buffered-reader/src/decompress_bzip2.rs @@ -8,7 +8,7 @@ use super::*; /// Decompresses the underlying `BufferedReader` using the bzip2 /// algorithm. -pub struct Bzip<R: BufferedReader<C>, C> { +pub struct Bzip<R: BufferedReader<C>, C: fmt::Debug> { reader: Generic<BzDecoder<R>, C>, } @@ -21,7 +21,7 @@ impl <R: BufferedReader<()>> Bzip<R, ()> { } } -impl <R: BufferedReader<C>, C> Bzip<R, C> { +impl <R: BufferedReader<C>, C: fmt::Debug> Bzip<R, C> { /// Like `new()`, but uses a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -34,13 +34,13 @@ impl <R: BufferedReader<C>, C> Bzip<R, C> { } } -impl<R: BufferedReader<C>, C> io::Read for Bzip<R, C> { +impl<R: BufferedReader<C>, C: fmt::Debug> io::Read for Bzip<R, C> { fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> { self.reader.read(buf) } } -impl<R: BufferedReader<C>, C> fmt::Debug for Bzip<R, C> { +impl<R: BufferedReader<C>, C: fmt::Debug> fmt::Debug for Bzip<R, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Bzip") .field("reader", &self.get_ref().unwrap()) @@ -48,13 +48,13 @@ impl<R: BufferedReader<C>, C> fmt::Debug for Bzip<R, C> { } } -impl<R: BufferedReader<C>, C> fmt::Display for Bzip<R, C> { +impl<R: BufferedReader<C>, C: fmt::Debug> fmt::Display for Bzip<R, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Bzip") } } -impl<R: BufferedReader<C>, C> BufferedReader<C> for Bzip<R, C> { +impl<R: BufferedReader<C>, C: fmt::Debug> BufferedReader<C> for Bzip<R, C> { fn buffer(&self) -> &[u8] { return self.reader.buffer(); } diff --git a/buffered-reader/src/decompress_deflate.rs b/buffered-reader/src/decompress_deflate.rs index de6210e7..647172fb 100644 --- a/buffered-reader/src/decompress_deflate.rs +++ b/buffered-reader/src/decompress_deflate.rs @@ -8,7 +8,7 @@ use super::*; /// Decompresses the underlying `BufferedReader` using the deflate /// algorithm. -pub struct Deflate<R: BufferedReader<C>, C> { +pub struct Deflate<R: BufferedReader<C>, C: fmt::Debug> { reader: Generic<DeflateDecoder<R>, C>, } @@ -21,7 +21,7 @@ impl <R: BufferedReader<()>> Deflate<R, ()> { } } -impl <R: BufferedReader<C>, C> Deflate<R, C> { +impl <R: BufferedReader<C>, C: fmt::Debug> Deflate<R, C> { /// Like `new()`, but uses a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -34,19 +34,19 @@ impl <R: BufferedReader<C>, C> Deflate<R, C> { } } -impl<R: BufferedReader<C>, C> io::Read for Deflate<R, C> { +impl<R: BufferedReader<C>, C: fmt::Debug> io::Read for Deflate<R, C> { fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> { self.reader.read(buf) } } -impl<R: BufferedReader<C>, C> fmt::Display for Deflate<R, C> { +impl<R: BufferedReader<C>, C: fmt::Debug> fmt::Display for Deflate<R, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Deflate") } } -impl<R: BufferedReader<C>, C> fmt::Debug for Deflate<R, C> { +impl<R: BufferedReader<C>, C: fmt::Debug> fmt::Debug for Deflate<R, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Deflate") .field("reader", &self.get_ref().unwrap()) @@ -54,7 +54,7 @@ impl<R: BufferedReader<C>, C> fmt::Debug for Deflate<R, C> { } } -impl<R: BufferedReader<C>, C> BufferedReader<C> +impl<R: BufferedReader<C>, C: fmt::Debug> BufferedReader<C> for Deflate<R, C> { fn buffer(&self) -> &[u8] { return self.reader.buffer(); @@ -130,7 +130,7 @@ impl<R: BufferedReader<C>, C> BufferedReader<C> /// Decompresses the underlying `BufferedReader` using the zlib /// algorithm. -pub struct Zlib<R: BufferedReader<C>, C> { +pub struct Zlib<R: BufferedReader<C>, C: fmt::Debug> { reader: Generic<ZlibDecoder<R>, C>, } @@ -143,7 +143,7 @@ impl <R: BufferedReader<()>> Zlib<R, ()> { } } -impl <R: BufferedReader<C>, C> Zlib<R, C> { +impl <R: BufferedReader<C>, C: fmt::Debug> Zlib<R, C> { /// Like `new()`, but uses a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -156,19 +156,19 @@ impl <R: BufferedReader<C>, C> Zlib<R, C> { } } -impl<R: BufferedReader<C>, C> io::Read for Zlib<R, C> { +impl<R: BufferedReader<C>, C: fmt::Debug> io::Read for Zlib<R, C> { fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> { self.reader.read(buf) } } -impl<R: BufferedReader<C>, C> fmt::Display for Zlib<R, C> { +impl<R: BufferedReader<C>, C: fmt::Debug> fmt::Display for Zlib<R, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Zlib") } } -impl<R: BufferedReader<C>, C> fmt::Debug for Zlib<R, C> { +impl<R: BufferedReader<C>, C: fmt::Debug> fmt::Debug for Zlib<R, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Zlib") .field("reader", &self.get_ref().unwrap()) @@ -176,7 +176,7 @@ impl<R: BufferedReader<C>, C> fmt::Debug for Zlib<R, C> { } } -impl<R: BufferedReader<C>, C> BufferedReader<C> +impl<R: BufferedReader<C>, C: fmt::Debug> BufferedReader<C> for Zlib<R, C> { fn buffer(&self) -> &[u8] { return self.reader.buffer(); diff --git a/buffered-reader/src/dup.rs b/buffered-reader/src/dup.rs index d2573dce..8a8e5067 100644 --- a/buffered-reader/src/dup.rs +++ b/buffered-reader/src/dup.rs @@ -10,7 +10,7 @@ use super::*; /// Note: this will likely cause the underlying stream to buffer as /// much data as you read. Thus, it should only be used for peeking /// at the underlying `BufferedReader`. -pub struct Dup<T: BufferedReader<C>, C> { +pub struct Dup<T: BufferedReader<C>, C: fmt::Debug> { reader: T, // The number of bytes that have been consumed. @@ -20,14 +20,14 @@ pub struct Dup<T: BufferedReader<C>, C> { cookie: C, } -impl<T: BufferedReader<C>, C> fmt::Display for Dup<T, C> { +impl<T: BufferedReader<C>, C: fmt::Debug> fmt::Display for Dup<T, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Dup ({} bytes consumed)", self.cursor) } } -impl<T: BufferedReader<C>, C> fmt::Debug for Dup<T, C> { +impl<T: BufferedReader<C>, C: fmt::Debug> fmt::Debug for Dup<T, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Dup") .field("cursor", &self.cursor) @@ -45,7 +45,7 @@ impl<T: BufferedReader<()>> Dup<T, ()> { } } -impl<T: BufferedReader<C>, C> Dup<T, C> { +impl<T: BufferedReader<C>, C: fmt::Debug> Dup<T, C> { /// Like `new()`, but uses a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -69,7 +69,7 @@ impl<T: BufferedReader<C>, C> Dup<T, C> { } } -impl<T: BufferedReader<C>, C> io::Read for Dup<T, C> { +impl<T: BufferedReader<C>, C: fmt::Debug> io::Read for Dup<T, C> { fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> { let data = self.reader.data(self.cursor + buf.len())?; assert!(data.len() >= self.cursor); @@ -84,7 +84,7 @@ impl<T: BufferedReader<C>, C> io::Read for Dup<T, C> { } } -impl<T: BufferedReader<C>, C> BufferedReader<C> for Dup<T, C> { +impl<T: BufferedReader<C>, C: fmt::Debug> BufferedReader<C> for Dup<T, C> { fn buffer(&self) -> &[u8] { let data = self.reader.buffer(); assert!(data.len() >= self.cursor); diff --git a/buffered-reader/src/eof.rs b/buffered-reader/src/eof.rs index 41d3d763..3371ef63 100644 --- a/buffered-reader/src/eof.rs +++ b/buffered-reader/src/eof.rs @@ -46,7 +46,7 @@ impl<C> Read for EOF<C> { } } -impl<C> BufferedReader<C> for EOF<C> { +impl<C: fmt::Debug> BufferedReader<C> for EOF<C> { fn buffer(&self) -> &[u8] { return &b""[..]; } diff --git a/buffered-reader/src/file_generic.rs b/buffered-reader/src/file_generic.rs index 0a073165..4a1cb830 100644 --- a/buffered-reader/src/file_generic.rs +++ b/buffered-reader/src/file_generic.rs @@ -10,15 +10,15 @@ use crate::file_error::FileError; /// /// This is a generic implementation that may be replaced by /// platform-specific versions. -pub struct File<C>(Generic<fs::File, C>, PathBuf); +pub struct File<C: fmt::Debug>(Generic<fs::File, C>, PathBuf); -impl<C> fmt::Display for File<C> { +impl<C: fmt::Debug> fmt::Display for File<C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "File {:?}", self.1.display()) } } -impl<C> fmt::Debug for File<C> { +impl<C: fmt::Debug> fmt::Debug for File<C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("File") .field(&self.0) @@ -34,7 +34,7 @@ impl File<()> { } } -impl<C> File<C> { +impl<C: fmt::Debug> File<C> { /// Like `open()`, but sets a cookie. pub fn with_cookie<P: AsRef<Path>>(path: P, cookie: C) -> io::Result<Self> { let path = path.as_ref(); @@ -43,14 +43,14 @@ impl<C> File<C> { } } -impl<C> io::Read for File<C> { +impl<C: fmt::Debug> io::Read for File<C> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.0.read(buf) .map_err(|e| FileError::new(&self.1, e)) } } -impl<C> BufferedReader<C> for File<C> { +impl<C: fmt::Debug> BufferedReader<C> for File<C> { fn buffer(&self) -> &[u8] { self.0.buffer() } diff --git a/buffered-reader/src/file_unix.rs b/buffered-reader/src/file_unix.rs index 7bc8b855..0b645f3c 100644 --- a/buffered-reader/src/file_unix.rs +++ b/buffered-reader/src/file_unix.rs @@ -25,15 +25,15 @@ const MMAP_THRESHOLD: u64 = 16 * 4096; /// /// This implementation tries to mmap the file, falling back to /// just using a generic reader. -pub struct File<'a, C>(Imp<'a, C>, PathBuf); +pub struct File<'a, C: fmt::Debug>(Imp<'a, C>, PathBuf); -impl<'a, C> fmt::Display for File<'a, C> { +impl<'a, C: fmt::Debug> fmt::Display for File<'a, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{} {:?}", self.0, self.1.display()) } } -impl<'a, C> fmt::Debug for File<'a, C> { +impl<'a, C: fmt::Debug> fmt::Debug for File<'a, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("File") .field(&self.0) @@ -43,7 +43,7 @@ impl<'a, C> fmt::Debug for File<'a, C> { } /// The implementation. -enum Imp<'a, C> { +enum Imp<'a, C: fmt::Debug> { Generic(Generic<fs::File, C>), MMAP { addr: *mut c_void, @@ -52,7 +52,7 @@ enum Imp<'a, C> { } } -impl<'a, C> Drop for Imp<'a, C> { +impl<'a, C: fmt::Debug> Drop for Imp<'a, C> { fn drop(&mut self) { match self { Imp::Generic(_) => (), @@ -64,7 +64,7 @@ impl<'a, C> Drop for Imp<'a, C> { } } -impl<'a, C> fmt::Display for Imp<'a, C> { +impl<'a, C: fmt::Debug> fmt::Display for Imp<'a, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "File(")?; match self { @@ -75,7 +75,7 @@ impl<'a, C> fmt::Display for Imp<'a, C> { } } -impl<'a, C> fmt::Debug for Imp<'a, C> { +impl<'a, C: fmt::Debug> fmt::Debug for Imp<'a, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Imp::Generic(ref g) => @@ -99,7 +99,7 @@ impl<'a> File<'a, ()> { } } -impl<'a, C> File<'a, C> { +impl<'a, C: fmt::Debug> File<'a, C> { /// Like `open()`, but sets a cookie. pub fn with_cookie<P: AsRef<Path>>(path: P, cookie: C) -> io::Result<Self> { let path = path.as_ref(); @@ -159,7 +159,7 @@ impl<'a, C> File<'a, C> { } } -impl<'a, C> io::Read for File<'a, C> { +impl<'a, C: fmt::Debug> io::Read for File<'a, C> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { match self.0 { Imp::Generic(ref mut reader) => reader.read(buf), @@ -168,7 +168,7 @@ impl<'a, C> io::Read for File<'a, C> { } } -impl<'a, C> BufferedReader<C> for File<'a, C> { +impl<'a, C: fmt::Debug> BufferedReader<C> for File<'a, C> { fn buffer(&self) -> &[u8] { match self.0 { Imp::Generic(ref reader) => reader.buffer(), diff --git a/buffered-reader/src/generic.rs b/buffered-reader/src/generic.rs index 12c28d3b..2332950e 100644 --- a/buffered-reader/src/generic.rs +++ b/buffered-reader/src/generic.rs @@ -13,7 +13,7 @@ use super::*; /// /// [`File`]: struct.File.html /// [`Memory`]: struct.Memory.html -pub struct Generic<T: io::Read, C> { +pub struct Generic<T: io::Read, C: fmt::Debug> { buffer: Option<Box<[u8]>>, // The next byte to read in the buffer. cursor: usize, @@ -28,13 +28,13 @@ pub struct Generic<T: io::Read, C> { cookie: C, } -impl<T: io::Read, C> fmt::Display for Generic<T, C> { +impl<T: io::Read, C: fmt::Debug> fmt::Display for Generic<T, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Generic") } } -impl<T: io::Read, C> fmt::Debug for Generic<T, C> { +impl<T: io::Read, C: fmt::Debug> fmt::Debug for Generic<T, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let buffered_data = if let Some(ref buffer) = self.buffer { buffer.len() - self.cursor @@ -59,7 +59,7 @@ impl<T: io::Read> Generic<T, ()> { } } -impl<T: io::Read, C> Generic<T, C> { +impl<T: io::Read, C: fmt::Debug> Generic<T, C> { /// Like `new()`, but sets a cookie, which can be retrieved using /// the `cookie_ref` and `cookie_mut` methods, and set using /// the `cookie_set` method. @@ -202,13 +202,13 @@ impl<T: io::Read, C> Generic<T, C> { } } -impl<T: io::Read, C> io::Read for Generic<T, C> { +impl<T: io::Read, C: fmt::Debug> io::Read for Generic<T, C> { fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> { return buffered_reader_generic_read_impl(self, buf); } } -impl<T: io::Read, C> BufferedReader<C> for Generic<T, C> { +impl<T: io::Read, C: fmt::Debug> BufferedReader<C> for Generic<T, C> { fn buffer(&self) -> &[u8] { if let Some(ref buffer) = self.buffer { &buffer[self.cursor..] diff --git a/buffered-reader/src/lib.rs b/buffered-reader/src/lib.rs index 79a9cb63..2b9a37b9 100644 --- a/buffered-reader/src/lib.rs +++ b/buffered-reader/src/lib.rs @@ -297,7 +297,9 @@ fn vec_truncate(v: &mut Vec<u8>, len: usize) { } /// The generic `BufferReader` interface. -pub trait BufferedReader<C> : io::Read + fmt::Debug + fmt::Display { +pub trait BufferedReader<C> : io::Read + fmt::Debug + fmt::Display + where C: fmt::Debug +{ /// Returns a reference to the internal buffer. /// /// Note: this returns the same data as `self.data(0)`, but it @@ -884,7 +886,7 @@ pub trait BufferedReader<C> : io::Read + fmt::Debug + fmt::Display { /// /// but, alas, Rust doesn't like that ("error\[E0119\]: conflicting /// implementations of trait `std::io::Read` for type `&mut _`"). -pub fn buffered_reader_generic_read_impl<T: BufferedReader<C>, C> +pub fn buffered_reader_generic_read_impl<T: BufferedReader<C>, C: fmt::Debug> (bio: &mut T, buf: &mut [u8]) -> Result<usize, io::Error> { match bio.data_consume(buf.len()) { Ok(inner) => { @@ -897,7 +899,7 @@ pub fn buffered_reader_generic_read_impl<T: BufferedReader<C>, C> } /// Make a `Box<BufferedReader>` look like a BufferedReader. -impl <'a, C> BufferedReader<C> for Box<dyn BufferedReader<C> + 'a> { +impl <'a, C: fmt::Debug> BufferedReader<C> for Box<dyn BufferedReader<C> + 'a> { fn buffer(&self) -> &[u8] { return self.as_ref().buffer(); } @@ -995,7 +997,7 @@ impl <'a, C> BufferedReader<C> for Box<dyn BufferedReader<C> + 'a> { // // for i in $(seq 0 9999); do printf "%04d\n" $i; done > buffered-reader-test.txt #[cfg(test)] -fn buffered_reader_test_data_check<'a, T: BufferedReader<C> + 'a, C>(bio: &mut T) { +fn buffered_reader_test_data_check<'a, T: BufferedReader<C> + 'a, C: fmt::Debug>(bio: &mut T) { use std::str; for i in 0 .. 10000 { @@ -1049,7 +1051,7 @@ mod test { } #[cfg(test)] - fn buffered_reader_read_test_aux<'a, T: BufferedReader<C> + 'a, C> + fn buffered_reader_read_test_aux<'a, T: BufferedReader<C> + 'a, C: fmt::Debug> (mut bio: T, data: &[u8]) { let mut buffer = [0; 99]; diff --git a/buffered-reader/src/limitor.rs b/buffered-reader/src/limitor.rs index a8588032..82bde9f9 100644 --- a/buffered-reader/src/limitor.rs +++ b/buffered-reader/src/limitor.rs @@ -5,20 +5,20 @@ use super::*; /// Limits the amount of data that can be read from a /// `BufferedReader`. -pub struct Limitor<T: BufferedReader<C>, C> { +pub struct Limitor<T: BufferedReader<C>, C: fmt::Debug> { reader: T, limit: u64, cookie: C, } -impl<T: BufferedReader<C>, C> fmt::Display for Limitor<T, C> { +impl<T: BufferedReader<C>, C: fmt::Debug> fmt::Display for Limitor<T, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Limitor ({} bytes)", self.limit) } } -impl<T: BufferedReader<C>, C> fmt::Debug for Limitor<T, C> { +impl<T: BufferedReader<C>, C: fmt::Debug> fmt::Debug for Limitor<T, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Limitor") .field("limit", &self.limit) @@ -37,7 +37,7 @@ impl<T: BufferedReader<()>> Limitor<T, ()> { } } -impl<T: BufferedReader<C>, C> Limitor<T, C> { +impl<T: BufferedReader<C>, C: fmt::Debug> Limitor<T, C> { /// Like `new()`, but sets a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -52,7 +52,7 @@ impl<T: BufferedReader<C>, C> Limitor<T, C> { } } -impl<T: BufferedReader<C>, C> io::Read for Limitor<T, C> { +impl<T: BufferedReader<C>, C: fmt::Debug> io::Read for Limitor<T, C> { fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> { let len = cmp::min(self.limit, buf.len() as u64) as usize; let result = self.reader.read(&mut buf[0..len]); @@ -63,7 +63,7 @@ impl<T: BufferedReader<C>, C> io::Read for Limitor<T, C> { } } -impl<T: BufferedReader<C>, C> BufferedReader<C> for Limitor<T, C> { +impl<T: BufferedReader<C>, C: fmt::Debug> BufferedReader<C> for Limitor<T, C> { fn buffer(&self) -> &[u8] { let buf = self.reader.buffer(); &buf[..cmp::min(buf.len(), diff --git a/buffered-reader/src/memory.rs b/buffered-reader/src/memory.rs index 7647f4ea..565cd4c5 100644 --- a/buffered-reader/src/memory.rs +++ b/buffered-reader/src/memory.rs @@ -11,7 +11,7 @@ use super::*; /// Although it is possible to use `Generic` to wrap a /// buffer, this implementation is optimized for a memory buffer, and /// avoids double buffering. -pub struct Memory<'a, C> { +pub struct Memory<'a, C: fmt::Debug> { buffer: &'a [u8], // The next byte to read in the buffer. cursor: usize, @@ -20,14 +20,14 @@ pub struct Memory<'a, C> { cookie: C, } -impl<'a, C> fmt::Display for Memory<'a, C> { +impl<'a, C: fmt::Debug> fmt::Display for Memory<'a, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Memory ({} of {} bytes read)", self.cursor, self.buffer.len()) } } -impl<'a, C> fmt::Debug for Memory<'a, C> { +impl<'a, C: fmt::Debug> fmt::Debug for Memory<'a, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Memory") .field("buffer (bytes)", &&self.buffer.len()) @@ -45,7 +45,7 @@ impl<'a> Memory<'a, ()> { } } -impl<'a, C> Memory<'a, C> { +impl<'a, C: fmt::Debug> Memory<'a, |