From 227db80b9d40526387f1e4a64f90464618fb885b Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 9 Dec 2020 20:26:52 +0100 Subject: buffered-reader: Require Cookies to be Send and Sync. - This way the entire `BufferedReader` will be `Send` and `Sync`. - Modify all other crates accordingly. - See #615. --- buffered-reader/src/adapter.rs | 12 ++++++------ buffered-reader/src/decompress_bzip2.rs | 10 +++++----- buffered-reader/src/decompress_deflate.rs | 22 +++++++++++----------- buffered-reader/src/dup.rs | 10 +++++----- buffered-reader/src/eof.rs | 2 +- buffered-reader/src/file_generic.rs | 12 ++++++------ buffered-reader/src/file_unix.rs | 20 ++++++++++---------- buffered-reader/src/generic.rs | 14 +++++++------- buffered-reader/src/lib.rs | 12 ++++++------ buffered-reader/src/limitor.rs | 10 +++++----- buffered-reader/src/memory.rs | 10 +++++----- buffered-reader/src/reserve.rs | 12 ++++++------ 12 files changed, 73 insertions(+), 73 deletions(-) (limited to 'buffered-reader') diff --git a/buffered-reader/src/adapter.rs b/buffered-reader/src/adapter.rs index 65c7a8aa..3734d9bc 100644 --- a/buffered-reader/src/adapter.rs +++ b/buffered-reader/src/adapter.rs @@ -10,7 +10,7 @@ use super::*; /// `Adapter` also changes cookie types, but does no buffering of its /// own. #[derive(Debug)] -pub struct Adapter, B: fmt::Debug, C: fmt::Debug> { +pub struct Adapter, B: fmt::Debug + Send + Sync, C: fmt::Debug + Sync + Send> { reader: T, _ghostly_cookie: std::marker::PhantomData, cookie: C, @@ -21,13 +21,13 @@ assert_send_and_sync!(Adapter B: fmt::Debug, C: fmt::Debug); -impl, B: fmt::Debug, C: fmt::Debug> fmt::Display for Adapter { +impl, B: fmt::Debug + Send + Sync, C: fmt::Debug + Sync + Send> fmt::Display for Adapter { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Adapter").finish() } } -impl, B: fmt::Debug> Adapter { +impl, B: fmt::Debug + Sync + Send> Adapter { /// Instantiates a new adapter. /// /// `reader` is the source to wrap. @@ -36,7 +36,7 @@ impl, B: fmt::Debug> Adapter { } } -impl, B: fmt::Debug, C: fmt::Debug> Adapter { +impl, B: fmt::Debug + Send + Sync, C: fmt::Debug + Sync + Send> Adapter { /// Like `new()`, but sets a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -51,13 +51,13 @@ impl, B: fmt::Debug, C: fmt::Debug> Adapter { } } -impl, B: fmt::Debug, C: fmt::Debug> io::Read for Adapter { +impl, B: fmt::Debug + Send + Sync, C: fmt::Debug + Sync + Send> io::Read for Adapter { fn read(&mut self, buf: &mut [u8]) -> Result { self.reader.read(buf) } } -impl, B: fmt::Debug, C: fmt::Debug> BufferedReader for Adapter { +impl, B: fmt::Debug + Send + Sync, C: fmt::Debug + Sync + Send> BufferedReader for Adapter { fn buffer(&self) -> &[u8] { self.reader.buffer() } diff --git a/buffered-reader/src/decompress_bzip2.rs b/buffered-reader/src/decompress_bzip2.rs index 8902c2af..febe37fc 100644 --- a/buffered-reader/src/decompress_bzip2.rs +++ b/buffered-reader/src/decompress_bzip2.rs @@ -9,7 +9,7 @@ use super::*; /// Decompresses the underlying `BufferedReader` using the bzip2 /// algorithm. #[derive(Debug)] -pub struct Bzip, C: fmt::Debug> { +pub struct Bzip, C: fmt::Debug + Sync + Send> { reader: Generic, C>, } @@ -26,7 +26,7 @@ impl > Bzip { } } -impl , C: fmt::Debug> Bzip { +impl , C: fmt::Debug + Sync + Send> Bzip { /// Like `new()`, but uses a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -39,19 +39,19 @@ impl , C: fmt::Debug> Bzip { } } -impl, C: fmt::Debug> io::Read for Bzip { +impl, C: fmt::Debug + Sync + Send> io::Read for Bzip { fn read(&mut self, buf: &mut [u8]) -> Result { self.reader.read(buf) } } -impl, C: fmt::Debug> fmt::Display for Bzip { +impl, C: fmt::Debug + Sync + Send> fmt::Display for Bzip { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Bzip").finish() } } -impl, C: fmt::Debug> BufferedReader for Bzip { +impl, C: fmt::Debug + Send + Sync> BufferedReader for Bzip { 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 43084a5f..d1d1a16b 100644 --- a/buffered-reader/src/decompress_deflate.rs +++ b/buffered-reader/src/decompress_deflate.rs @@ -9,7 +9,7 @@ use super::*; /// Decompresses the underlying `BufferedReader` using the deflate /// algorithm. #[derive(Debug)] -pub struct Deflate, C: fmt::Debug> { +pub struct Deflate, C: fmt::Debug + Sync + Send> { reader: Generic, C>, } @@ -26,7 +26,7 @@ impl > Deflate { } } -impl , C: fmt::Debug> Deflate { +impl , C: fmt::Debug + Sync + Send> Deflate { /// Like `new()`, but uses a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -39,19 +39,19 @@ impl , C: fmt::Debug> Deflate { } } -impl, C: fmt::Debug> io::Read for Deflate { +impl, C: fmt::Debug + Sync + Send> io::Read for Deflate { fn read(&mut self, buf: &mut [u8]) -> Result { self.reader.read(buf) } } -impl, C: fmt::Debug> fmt::Display for Deflate { +impl, C: fmt::Debug + Sync + Send> fmt::Display for Deflate { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Deflate").finish() } } -impl, C: fmt::Debug> BufferedReader +impl, C: fmt::Debug + Send + Sync> BufferedReader for Deflate { fn buffer(&self) -> &[u8] { return self.reader.buffer(); @@ -127,7 +127,7 @@ impl, C: fmt::Debug> BufferedReader /// Decompresses the underlying `BufferedReader` using the zlib /// algorithm. -pub struct Zlib, C: fmt::Debug> { +pub struct Zlib, C: fmt::Debug + Sync + Send> { reader: Generic, C>, } @@ -144,7 +144,7 @@ impl > Zlib { } } -impl , C: fmt::Debug> Zlib { +impl , C: fmt::Debug + Sync + Send> Zlib { /// Like `new()`, but uses a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -157,19 +157,19 @@ impl , C: fmt::Debug> Zlib { } } -impl, C: fmt::Debug> io::Read for Zlib { +impl, C: fmt::Debug + Sync + Send> io::Read for Zlib { fn read(&mut self, buf: &mut [u8]) -> Result { self.reader.read(buf) } } -impl, C: fmt::Debug> fmt::Display for Zlib { +impl, C: fmt::Debug + Sync + Send> fmt::Display for Zlib { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Zlib") } } -impl, C: fmt::Debug> fmt::Debug for Zlib { +impl, C: fmt::Debug + Sync + Send> fmt::Debug for Zlib { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Zlib") .field("reader", &self.get_ref().unwrap()) @@ -177,7 +177,7 @@ impl, C: fmt::Debug> fmt::Debug for Zlib { } } -impl, C: fmt::Debug> BufferedReader +impl, C: fmt::Debug + Send + Sync> BufferedReader for Zlib { fn buffer(&self) -> &[u8] { return self.reader.buffer(); diff --git a/buffered-reader/src/dup.rs b/buffered-reader/src/dup.rs index 50a9aa26..d7d3f7e5 100644 --- a/buffered-reader/src/dup.rs +++ b/buffered-reader/src/dup.rs @@ -11,7 +11,7 @@ use super::*; /// much data as you read. Thus, it should only be used for peeking /// at the underlying `BufferedReader`. #[derive(Debug)] -pub struct Dup, C: fmt::Debug> { +pub struct Dup, C: fmt::Debug + Sync + Send> { reader: T, // The number of bytes that have been consumed. @@ -25,7 +25,7 @@ assert_send_and_sync!(Dup where T: BufferedReader, C: fmt::Debug); -impl, C: fmt::Debug> fmt::Display for Dup { +impl, C: fmt::Debug + Sync + Send> fmt::Display for Dup { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Dup") .field("cursor", &self.cursor) @@ -42,7 +42,7 @@ impl> Dup { } } -impl, C: fmt::Debug> Dup { +impl, C: fmt::Debug + Sync + Send> Dup { /// Like `new()`, but uses a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -66,7 +66,7 @@ impl, C: fmt::Debug> Dup { } } -impl, C: fmt::Debug> io::Read for Dup { +impl, C: fmt::Debug + Sync + Send> io::Read for Dup { fn read(&mut self, buf: &mut [u8]) -> Result { let data = self.reader.data(self.cursor + buf.len())?; assert!(data.len() >= self.cursor); @@ -81,7 +81,7 @@ impl, C: fmt::Debug> io::Read for Dup { } } -impl, C: fmt::Debug> BufferedReader for Dup { +impl, C: fmt::Debug + Send + Sync> BufferedReader for Dup { 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 c21ecde9..b0312630 100644 --- a/buffered-reader/src/eof.rs +++ b/buffered-reader/src/eof.rs @@ -44,7 +44,7 @@ impl Read for EOF { } } -impl BufferedReader for EOF { +impl BufferedReader for EOF { fn buffer(&self) -> &[u8] { return &b""[..]; } diff --git a/buffered-reader/src/file_generic.rs b/buffered-reader/src/file_generic.rs index cc9f1367..2c61e571 100644 --- a/buffered-reader/src/file_generic.rs +++ b/buffered-reader/src/file_generic.rs @@ -10,18 +10,18 @@ use crate::file_error::FileError; /// /// This is a generic implementation that may be replaced by /// platform-specific versions. -pub struct File(Generic, PathBuf); +pub struct File(Generic, PathBuf); assert_send_and_sync!(File where C: fmt::Debug); -impl fmt::Display for File { +impl fmt::Display for File { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "File {:?}", self.1.display()) } } -impl fmt::Debug for File { +impl fmt::Debug for File { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("File") .field(&self.0) @@ -37,7 +37,7 @@ impl File<()> { } } -impl File { +impl File { /// Like `open()`, but sets a cookie. pub fn with_cookie>(path: P, cookie: C) -> io::Result { let path = path.as_ref(); @@ -46,14 +46,14 @@ impl File { } } -impl io::Read for File { +impl io::Read for File { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.0.read(buf) .map_err(|e| FileError::new(&self.1, e)) } } -impl BufferedReader for File { +impl BufferedReader for File { fn buffer(&self) -> &[u8] { self.0.buffer() } diff --git a/buffered-reader/src/file_unix.rs b/buffered-reader/src/file_unix.rs index 9502021f..a1298737 100644 --- a/buffered-reader/src/file_unix.rs +++ b/buffered-reader/src/file_unix.rs @@ -25,18 +25,18 @@ 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: fmt::Debug>(Imp<'a, C>, PathBuf); +pub struct File<'a, C: fmt::Debug + Sync + Send>(Imp<'a, C>, PathBuf); assert_send_and_sync!(File<'_, C> where C: fmt::Debug); -impl<'a, C: fmt::Debug> fmt::Display for File<'a, C> { +impl<'a, C: fmt::Debug + Sync + Send> 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> fmt::Debug for File<'a, C> { +impl<'a, C: fmt::Debug + Sync + Send> fmt::Debug for File<'a, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("File") .field(&self.0) @@ -46,14 +46,14 @@ impl<'a, C: fmt::Debug> fmt::Debug for File<'a, C> { } /// The implementation. -enum Imp<'a, C: fmt::Debug> { +enum Imp<'a, C: fmt::Debug + Sync + Send> { Generic(Generic), MMAP { reader: Memory<'a, C>, } } -impl<'a, C: fmt::Debug> Drop for Imp<'a, C> { +impl<'a, C: fmt::Debug + Sync + Send> Drop for Imp<'a, C> { fn drop(&mut self) { match self { Imp::Generic(_) => (), @@ -67,7 +67,7 @@ impl<'a, C: fmt::Debug> Drop for Imp<'a, C> { } } -impl<'a, C: fmt::Debug> fmt::Display for Imp<'a, C> { +impl<'a, C: fmt::Debug + Sync + Send> fmt::Display for Imp<'a, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "File(")?; match self { @@ -78,7 +78,7 @@ impl<'a, C: fmt::Debug> fmt::Display for Imp<'a, C> { } } -impl<'a, C: fmt::Debug> fmt::Debug for Imp<'a, C> { +impl<'a, C: fmt::Debug + Sync + Send> fmt::Debug for Imp<'a, C> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Imp::Generic(ref g) => @@ -102,7 +102,7 @@ impl<'a> File<'a, ()> { } } -impl<'a, C: fmt::Debug> File<'a, C> { +impl<'a, C: fmt::Debug + Sync + Send> File<'a, C> { /// Like `open()`, but sets a cookie. pub fn with_cookie>(path: P, cookie: C) -> io::Result { let path = path.as_ref(); @@ -160,7 +160,7 @@ impl<'a, C: fmt::Debug> File<'a, C> { } } -impl<'a, C: fmt::Debug> io::Read for File<'a, C> { +impl<'a, C: fmt::Debug + Sync + Send> io::Read for File<'a, C> { fn read(&mut self, buf: &mut [u8]) -> io::Result { match self.0 { Imp::Generic(ref mut reader) => reader.read(buf), @@ -169,7 +169,7 @@ impl<'a, C: fmt::Debug> io::Read for File<'a, C> { } } -impl<'a, C: fmt::Debug> BufferedReader for File<'a, C> { +impl<'a, C: fmt::Debug + Sync + Send> BufferedReader 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 25c56272..d2e9acfa 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 { +pub struct Generic { buffer: Option>, // The next byte to read in the buffer. cursor: usize, @@ -32,13 +32,13 @@ assert_send_and_sync!(Generic where T: io::Read, C: fmt::Debug); -impl fmt::Display for Generic { +impl fmt::Display for Generic { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Generic") } } -impl fmt::Debug for Generic { +impl fmt::Debug for Generic { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let buffered_data = if let Some(ref buffer) = self.buffer { buffer.len() - self.cursor @@ -53,7 +53,7 @@ impl fmt::Debug for Generic { } } -impl Generic { +impl Generic { /// Instantiate a new generic reader. `reader` is the source to /// wrap. `preferred_chuck_size` is the preferred chuck size. If /// None, then the default will be used, which is usually what you @@ -63,7 +63,7 @@ impl Generic { } } -impl Generic { +impl Generic { /// 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. @@ -206,13 +206,13 @@ impl Generic { } } -impl io::Read for Generic { +impl io::Read for Generic { fn read(&mut self, buf: &mut [u8]) -> Result { return buffered_reader_generic_read_impl(self, buf); } } -impl BufferedReader for Generic { +impl BufferedReader for Generic { 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 45c12726..f146741d 100644 --- a/buffered-reader/src/lib.rs +++ b/buffered-reader/src/lib.rs @@ -300,8 +300,8 @@ fn vec_truncate(v: &mut Vec, len: usize) { } /// The generic `BufferReader` interface. -pub trait BufferedReader : io::Read + fmt::Debug + fmt::Display - where C: fmt::Debug +pub trait BufferedReader : io::Read + fmt::Debug + fmt::Display + Send + Sync + where C: fmt::Debug + Send + Sync { /// Returns a reference to the internal buffer. /// @@ -907,7 +907,7 @@ pub trait BufferedReader : 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, C: fmt::Debug> +pub fn buffered_reader_generic_read_impl, C: fmt::Debug + Sync + Send> (bio: &mut T, buf: &mut [u8]) -> Result { match bio.data_consume(buf.len()) { Ok(inner) => { @@ -920,7 +920,7 @@ pub fn buffered_reader_generic_read_impl, C: fmt::Debug> } /// Make a `Box` look like a BufferedReader. -impl <'a, C: fmt::Debug> BufferedReader for Box + 'a> { +impl <'a, C: fmt::Debug + Sync + Send> BufferedReader for Box + 'a> { fn buffer(&self) -> &[u8] { return self.as_ref().buffer(); } @@ -1018,7 +1018,7 @@ impl <'a, C: fmt::Debug> BufferedReader for Box + '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 + 'a, C: fmt::Debug>(bio: &mut T) { +fn buffered_reader_test_data_check<'a, T: BufferedReader + 'a, C: fmt::Debug + Sync + Send>(bio: &mut T) { use std::str; for i in 0 .. 10000 { @@ -1072,7 +1072,7 @@ mod test { } #[cfg(test)] - fn buffered_reader_read_test_aux<'a, T: BufferedReader + 'a, C: fmt::Debug> + fn buffered_reader_read_test_aux<'a, T: BufferedReader + 'a, C: fmt::Debug + Sync + Send> (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 de75ee5e..16f3897e 100644 --- a/buffered-reader/src/limitor.rs +++ b/buffered-reader/src/limitor.rs @@ -6,7 +6,7 @@ use super::*; /// Limits the amount of data that can be read from a /// `BufferedReader`. #[derive(Debug)] -pub struct Limitor, C: fmt::Debug> { +pub struct Limitor, C: fmt::Debug + Sync + Send> { reader: T, limit: u64, @@ -17,7 +17,7 @@ assert_send_and_sync!(Limitor where T: BufferedReader, C: fmt::Debug); -impl, C: fmt::Debug> fmt::Display for Limitor { +impl, C: fmt::Debug + Sync + Send> fmt::Display for Limitor { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Limitor") .field("limit", &self.limit) @@ -35,7 +35,7 @@ impl> Limitor { } } -impl, C: fmt::Debug> Limitor { +impl, C: fmt::Debug + Sync + Send> Limitor { /// Like `new()`, but sets a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -50,7 +50,7 @@ impl, C: fmt::Debug> Limitor { } } -impl, C: fmt::Debug> io::Read for Limitor { +impl, C: fmt::Debug + Sync + Send> io::Read for Limitor { fn read(&mut self, buf: &mut [u8]) -> Result { let len = cmp::min(self.limit, buf.len() as u64) as usize; let result = self.reader.read(&mut buf[0..len]); @@ -61,7 +61,7 @@ impl, C: fmt::Debug> io::Read for Limitor { } } -impl, C: fmt::Debug> BufferedReader for Limitor { +impl, C: fmt::Debug + Sync + Send> BufferedReader for Limitor { 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 d13dd018..b469a652 100644 --- a/buffered-reader/src/memory.rs +++ b/buffered-reader/src/memory.rs @@ -12,7 +12,7 @@ use super::*; /// buffer, this implementation is optimized for a memory buffer, and /// avoids double buffering. #[derive(Debug)] -pub struct Memory<'a, C: fmt::Debug> { +pub struct Memory<'a, C: fmt::Debug + Sync + Send> { buffer: &'a [u8], // The next byte to read in the buffer. cursor: usize, @@ -24,7 +24,7 @@ pub struct Memory<'a, C: fmt::Debug> { assert_send_and_sync!(Memory<'_, C> where C: fmt::Debug); -impl<'a, C: fmt::Debug> fmt::Display for Memory<'a, C> { +impl<'a, C: fmt::Debug + Sync + Send> 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()) @@ -40,7 +40,7 @@ impl<'a> Memory<'a, ()> { } } -impl<'a, C: fmt::Debug> Memory<'a, C> { +impl<'a, C: fmt::Debug + Sync + Send> Memory<'a, C> { /// Like `new()`, but sets a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -65,7 +65,7 @@ impl<'a, C: fmt::Debug> Memory<'a, C> { } } -impl<'a, C: fmt::Debug> io::Read for Memory<'a, C> { +impl<'a, C: fmt::Debug + Sync + Send> io::Read for Memory<'a, C> { fn read(&mut self, buf: &mut [u8]) -> Result { let amount = cmp::min(buf.len(), self.buffer.len() - self.cursor); buf[0..amount].copy_from_slice( @@ -75,7 +75,7 @@ impl<'a, C: fmt::Debug> io::Read for Memory<'a, C> { } } -impl<'a, C: fmt::Debug> BufferedReader for Memory<'a, C> { +impl<'a, C: fmt::Debug + Sync + Send> BufferedReader for Memory<'a, C> { fn buffer(&self) -> &[u8] { &self.buffer[self.cursor..] } diff --git a/buffered-reader/src/reserve.rs b/buffered-reader/src/reserve.rs index b9c59b69..76d82124 100644 --- a/buffered-reader/src/reserve.rs +++ b/buffered-reader/src/reserve.rs @@ -10,7 +10,7 @@ use super::*; /// how much data can be read from the underlying `BufferedReader`, /// it causes at least N bytes to by buffered. #[derive(Debug)] -pub struct Reserve, C: fmt::Debug> { +pub struct Reserve, C: fmt::Debug + Sync + Send> { reader: T, reserve: usize, @@ -21,7 +21,7 @@ assert_send_and_sync!(Reserve where T: BufferedReader, C: fmt::Debug); -impl, C: fmt::Debug> fmt::Display for Reserve { +impl, C: fmt::Debug + Sync + Send> fmt::Display for Reserve { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Reserve") .field("reserve", &self.reserve) @@ -39,7 +39,7 @@ impl> Reserve { } } -impl, C: fmt::Debug> Reserve { +impl, C: fmt::Debug + Sync + Send> Reserve { /// Like `new()`, but sets a cookie. /// /// The cookie can be retrieved using the `cookie_ref` and @@ -54,7 +54,7 @@ impl, C: fmt::Debug> Reserve { } } -impl, C: fmt::Debug> io::Read for Reserve { +impl, C: fmt::Debug + Sync + Send> io::Read for Reserve { fn read(&mut self, buf: &mut [u8]) -> Result { let to_read = { let data = self.reader.data(buf.len() + self.reserve)?; @@ -71,7 +71,7 @@ impl, C: fmt::Debug> io::Read for Reserve { } } -impl, C: fmt::Debug> BufferedReader for Reserve { +impl, C: fmt::Debug + Send + Sync> BufferedReader for Reserve { fn buffer(&self) -> &[u8] { let buf = self.reader.buffer(); if buf.len() > self.reserve { @@ -171,7 +171,7 @@ mod test { // orig: [ | to_read | | ] // \ total / // - fn read_chunk<'a, R: BufferedReader, C: fmt::Debug>( + fn read_chunk<'a, R: BufferedReader, C: fmt::Debug + Sync + Send>( orig: &[u8], r: &mut R, to_read: usize, cursor: usize, total: usize, mode: usize) { -- cgit v1.2.3