forked from abdul124/rust-core_io
1894 lines
64 KiB
Diff
1894 lines
64 KiB
Diff
|
diff --git a/buffered.rs b/buffered.rs
|
||
|
index a14c10d..3e78c01 100644
|
||
|
--- a/buffered.rs
|
||
|
+++ b/buffered.rs
|
||
|
@@ -1,12 +1,12 @@
|
||
|
//! Buffering wrappers for I/O traits
|
||
|
|
||
|
+use core::prelude::v1::*;
|
||
|
use crate::io::prelude::*;
|
||
|
|
||
|
-use crate::cmp;
|
||
|
-use crate::error;
|
||
|
-use crate::fmt;
|
||
|
+use core::cmp;
|
||
|
+use core::fmt;
|
||
|
use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut};
|
||
|
-use crate::memchr;
|
||
|
+use io::memchr;
|
||
|
|
||
|
/// The `BufReader` struct adds buffering to any reader.
|
||
|
///
|
||
|
@@ -42,7 +42,6 @@ use crate::memchr;
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub struct BufReader<R> {
|
||
|
inner: R,
|
||
|
buf: Box<[u8]>,
|
||
|
@@ -66,7 +65,6 @@ impl<R: Read> BufReader<R> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn new(inner: R) -> BufReader<R> {
|
||
|
BufReader::with_capacity(DEFAULT_BUF_SIZE, inner)
|
||
|
}
|
||
|
@@ -87,7 +85,6 @@ impl<R: Read> BufReader<R> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn with_capacity(cap: usize, inner: R) -> BufReader<R> {
|
||
|
unsafe {
|
||
|
let mut buffer = Vec::with_capacity(cap);
|
||
|
@@ -122,7 +119,6 @@ impl<R> BufReader<R> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn get_ref(&self) -> &R { &self.inner }
|
||
|
|
||
|
/// Gets a mutable reference to the underlying reader.
|
||
|
@@ -143,7 +139,6 @@ impl<R> BufReader<R> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn get_mut(&mut self) -> &mut R { &mut self.inner }
|
||
|
|
||
|
/// Returns a reference to the internally buffered data.
|
||
|
@@ -168,7 +163,6 @@ impl<R> BufReader<R> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[unstable(feature = "bufreader_buffer", issue = "45323")]
|
||
|
pub fn buffer(&self) -> &[u8] {
|
||
|
&self.buf[self.pos..self.cap]
|
||
|
}
|
||
|
@@ -191,7 +185,6 @@ impl<R> BufReader<R> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn into_inner(self) -> R { self.inner }
|
||
|
}
|
||
|
|
||
|
@@ -200,7 +193,6 @@ impl<R: Seek> BufReader<R> {
|
||
|
/// the buffer will not be flushed, allowing for more efficient seeks.
|
||
|
/// This method does not return the location of the underlying reader, so the caller
|
||
|
/// must track this information themselves if it is required.
|
||
|
- #[unstable(feature = "bufreader_seek_relative", issue = "31100")]
|
||
|
pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> {
|
||
|
let pos = self.pos as u64;
|
||
|
if offset < 0 {
|
||
|
@@ -220,7 +212,6 @@ impl<R: Seek> BufReader<R> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<R: Read> Read for BufReader<R> {
|
||
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||
|
// If we don't have any buffered data and we're doing a massive read
|
||
|
@@ -256,7 +247,6 @@ impl<R: Read> Read for BufReader<R> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<R: Read> BufRead for BufReader<R> {
|
||
|
fn fill_buf(&mut self) -> io::Result<&[u8]> {
|
||
|
// If we've reached the end of our internal buffer then we need to fetch
|
||
|
@@ -276,7 +266,6 @@ impl<R: Read> BufRead for BufReader<R> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<R> fmt::Debug for BufReader<R> where R: fmt::Debug {
|
||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||
|
fmt.debug_struct("BufReader")
|
||
|
@@ -286,7 +275,6 @@ impl<R> fmt::Debug for BufReader<R> where R: fmt::Debug {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<R: Seek> Seek for BufReader<R> {
|
||
|
/// Seek to an offset, in bytes, in the underlying reader.
|
||
|
///
|
||
|
@@ -395,7 +383,6 @@ impl<R: Seek> Seek for BufReader<R> {
|
||
|
/// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write
|
||
|
/// [`TcpStream`]: ../../std/net/struct.TcpStream.html
|
||
|
/// [`flush`]: #method.flush
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub struct BufWriter<W: Write> {
|
||
|
inner: Option<W>,
|
||
|
buf: Vec<u8>,
|
||
|
@@ -430,7 +417,6 @@ pub struct BufWriter<W: Write> {
|
||
|
/// };
|
||
|
/// ```
|
||
|
#[derive(Debug)]
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub struct IntoInnerError<W>(W, Error);
|
||
|
|
||
|
impl<W: Write> BufWriter<W> {
|
||
|
@@ -445,7 +431,6 @@ impl<W: Write> BufWriter<W> {
|
||
|
///
|
||
|
/// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn new(inner: W) -> BufWriter<W> {
|
||
|
BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner)
|
||
|
}
|
||
|
@@ -463,7 +448,6 @@ impl<W: Write> BufWriter<W> {
|
||
|
/// let stream = TcpStream::connect("127.0.0.1:34254").unwrap();
|
||
|
/// let mut buffer = BufWriter::with_capacity(100, stream);
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn with_capacity(cap: usize, inner: W) -> BufWriter<W> {
|
||
|
BufWriter {
|
||
|
inner: Some(inner),
|
||
|
@@ -512,7 +496,6 @@ impl<W: Write> BufWriter<W> {
|
||
|
/// // we can use reference just like buffer
|
||
|
/// let reference = buffer.get_ref();
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() }
|
||
|
|
||
|
/// Gets a mutable reference to the underlying writer.
|
||
|
@@ -530,7 +513,6 @@ impl<W: Write> BufWriter<W> {
|
||
|
/// // we can use reference just like buffer
|
||
|
/// let reference = buffer.get_mut();
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() }
|
||
|
|
||
|
/// Returns a reference to the internally buffered data.
|
||
|
@@ -547,7 +529,6 @@ impl<W: Write> BufWriter<W> {
|
||
|
/// // See how many bytes are currently buffered
|
||
|
/// let bytes_buffered = buf_writer.buffer().len();
|
||
|
/// ```
|
||
|
- #[unstable(feature = "bufreader_buffer", issue = "45323")]
|
||
|
pub fn buffer(&self) -> &[u8] {
|
||
|
&self.buf
|
||
|
}
|
||
|
@@ -571,7 +552,6 @@ impl<W: Write> BufWriter<W> {
|
||
|
/// // unwrap the TcpStream and flush the buffer
|
||
|
/// let stream = buffer.into_inner().unwrap();
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn into_inner(mut self) -> Result<W, IntoInnerError<BufWriter<W>>> {
|
||
|
match self.flush_buf() {
|
||
|
Err(e) => Err(IntoInnerError(self, e)),
|
||
|
@@ -580,7 +560,6 @@ impl<W: Write> BufWriter<W> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<W: Write> Write for BufWriter<W> {
|
||
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||
|
if self.buf.len() + buf.len() > self.buf.capacity() {
|
||
|
@@ -616,7 +595,6 @@ impl<W: Write> Write for BufWriter<W> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<W: Write> fmt::Debug for BufWriter<W> where W: fmt::Debug {
|
||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||
|
fmt.debug_struct("BufWriter")
|
||
|
@@ -626,7 +604,6 @@ impl<W: Write> fmt::Debug for BufWriter<W> where W: fmt::Debug {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<W: Write + Seek> Seek for BufWriter<W> {
|
||
|
/// Seek to the offset, in bytes, in the underlying writer.
|
||
|
///
|
||
|
@@ -636,7 +613,6 @@ impl<W: Write + Seek> Seek for BufWriter<W> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<W: Write> Drop for BufWriter<W> {
|
||
|
fn drop(&mut self) {
|
||
|
if self.inner.is_some() && !self.panicked {
|
||
|
@@ -675,7 +651,6 @@ impl<W> IntoInnerError<W> {
|
||
|
/// }
|
||
|
/// };
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn error(&self) -> &Error { &self.1 }
|
||
|
|
||
|
/// Returns the buffered writer instance which generated the error.
|
||
|
@@ -708,23 +683,13 @@ impl<W> IntoInnerError<W> {
|
||
|
/// }
|
||
|
/// };
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn into_inner(self) -> W { self.0 }
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<W> From<IntoInnerError<W>> for Error {
|
||
|
fn from(iie: IntoInnerError<W>) -> Error { iie.1 }
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
-impl<W: Send + fmt::Debug> error::Error for IntoInnerError<W> {
|
||
|
- fn description(&self) -> &str {
|
||
|
- error::Error::description(self.error())
|
||
|
- }
|
||
|
-}
|
||
|
-
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<W> fmt::Display for IntoInnerError<W> {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||
|
self.error().fmt(f)
|
||
|
@@ -795,7 +760,6 @@ impl<W> fmt::Display for IntoInnerError<W> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub struct LineWriter<W: Write> {
|
||
|
inner: BufWriter<W>,
|
||
|
need_flush: bool,
|
||
|
@@ -816,7 +780,6 @@ impl<W: Write> LineWriter<W> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn new(inner: W) -> LineWriter<W> {
|
||
|
// Lines typically aren't that long, don't use a giant buffer
|
||
|
LineWriter::with_capacity(1024, inner)
|
||
|
@@ -837,7 +800,6 @@ impl<W: Write> LineWriter<W> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn with_capacity(cap: usize, inner: W) -> LineWriter<W> {
|
||
|
LineWriter {
|
||
|
inner: BufWriter::with_capacity(cap, inner),
|
||
|
@@ -861,7 +823,6 @@ impl<W: Write> LineWriter<W> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn get_ref(&self) -> &W { self.inner.get_ref() }
|
||
|
|
||
|
/// Gets a mutable reference to the underlying writer.
|
||
|
@@ -884,7 +845,6 @@ impl<W: Write> LineWriter<W> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() }
|
||
|
|
||
|
/// Unwraps this `LineWriter`, returning the underlying writer.
|
||
|
@@ -910,7 +870,6 @@ impl<W: Write> LineWriter<W> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn into_inner(self) -> Result<W, IntoInnerError<LineWriter<W>>> {
|
||
|
self.inner.into_inner().map_err(|IntoInnerError(buf, e)| {
|
||
|
IntoInnerError(LineWriter {
|
||
|
@@ -921,7 +880,6 @@ impl<W: Write> LineWriter<W> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<W: Write> Write for LineWriter<W> {
|
||
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||
|
if self.need_flush {
|
||
|
@@ -966,7 +924,6 @@ impl<W: Write> Write for LineWriter<W> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<W: Write> fmt::Debug for LineWriter<W> where W: fmt::Debug {
|
||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||
|
fmt.debug_struct("LineWriter")
|
||
|
diff --git a/cursor.rs b/cursor.rs
|
||
|
index 873da08..3d39e57 100644
|
||
|
--- a/cursor.rs
|
||
|
+++ b/cursor.rs
|
||
|
@@ -1,9 +1,10 @@
|
||
|
use crate::io::prelude::*;
|
||
|
|
||
|
-use crate::cmp;
|
||
|
-use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut};
|
||
|
+use core::cmp;
|
||
|
+use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind};
|
||
|
+#[cfg(feature="collections")] use crate::io::{IoVec, IoVecMut};
|
||
|
|
||
|
-use core::convert::TryInto;
|
||
|
+#[cfg(feature="collections")] use core::convert::TryInto;
|
||
|
|
||
|
/// A `Cursor` wraps an in-memory buffer and provides it with a
|
||
|
/// [`Seek`] implementation.
|
||
|
@@ -71,7 +72,6 @@ use core::convert::TryInto;
|
||
|
/// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||
|
/// }
|
||
|
/// ```
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
#[derive(Clone, Debug)]
|
||
|
pub struct Cursor<T> {
|
||
|
inner: T,
|
||
|
@@ -94,7 +94,6 @@ impl<T> Cursor<T> {
|
||
|
/// # fn force_inference(_: &Cursor<Vec<u8>>) {}
|
||
|
/// # force_inference(&buff);
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn new(inner: T) -> Cursor<T> {
|
||
|
Cursor { pos: 0, inner: inner }
|
||
|
}
|
||
|
@@ -112,7 +111,6 @@ impl<T> Cursor<T> {
|
||
|
///
|
||
|
/// let vec = buff.into_inner();
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn into_inner(self) -> T { self.inner }
|
||
|
|
||
|
/// Gets a reference to the underlying value in this cursor.
|
||
|
@@ -128,7 +126,6 @@ impl<T> Cursor<T> {
|
||
|
///
|
||
|
/// let reference = buff.get_ref();
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn get_ref(&self) -> &T { &self.inner }
|
||
|
|
||
|
/// Gets a mutable reference to the underlying value in this cursor.
|
||
|
@@ -147,7 +144,6 @@ impl<T> Cursor<T> {
|
||
|
///
|
||
|
/// let reference = buff.get_mut();
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn get_mut(&mut self) -> &mut T { &mut self.inner }
|
||
|
|
||
|
/// Returns the current position of this cursor.
|
||
|
@@ -169,7 +165,6 @@ impl<T> Cursor<T> {
|
||
|
/// buff.seek(SeekFrom::Current(-1)).unwrap();
|
||
|
/// assert_eq!(buff.position(), 1);
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn position(&self) -> u64 { self.pos }
|
||
|
|
||
|
/// Sets the position of this cursor.
|
||
|
@@ -189,11 +184,9 @@ impl<T> Cursor<T> {
|
||
|
/// buff.set_position(4);
|
||
|
/// assert_eq!(buff.position(), 4);
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn set_position(&mut self, pos: u64) { self.pos = pos; }
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<T> io::Seek for Cursor<T> where T: AsRef<[u8]> {
|
||
|
fn seek(&mut self, style: SeekFrom) -> io::Result<u64> {
|
||
|
let (base_pos, offset) = match style {
|
||
|
@@ -214,14 +207,14 @@ impl<T> io::Seek for Cursor<T> where T: AsRef<[u8]> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<T> Read for Cursor<T> where T: AsRef<[u8]> {
|
||
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||
|
- let n = Read::read(&mut self.fill_buf()?, buf)?;
|
||
|
+ let n = Read::read(&mut self.get_buf()?, buf)?;
|
||
|
self.pos += n as u64;
|
||
|
Ok(n)
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result<usize> {
|
||
|
let mut nread = 0;
|
||
|
for buf in bufs {
|
||
|
@@ -236,7 +229,7 @@ impl<T> Read for Cursor<T> where T: AsRef<[u8]> {
|
||
|
|
||
|
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
|
||
|
let n = buf.len();
|
||
|
- Read::read_exact(&mut self.fill_buf()?, buf)?;
|
||
|
+ Read::read_exact(&mut self.get_buf()?, buf)?;
|
||
|
self.pos += n as u64;
|
||
|
Ok(())
|
||
|
}
|
||
|
@@ -247,12 +240,16 @@ impl<T> Read for Cursor<T> where T: AsRef<[u8]> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
-impl<T> BufRead for Cursor<T> where T: AsRef<[u8]> {
|
||
|
- fn fill_buf(&mut self) -> io::Result<&[u8]> {
|
||
|
+impl<T> Cursor<T> where T: AsRef<[u8]> {
|
||
|
+ fn get_buf(&mut self) -> io::Result<&[u8]> {
|
||
|
let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64);
|
||
|
Ok(&self.inner.as_ref()[(amt as usize)..])
|
||
|
}
|
||
|
+}
|
||
|
+
|
||
|
+#[cfg(feature="collections")]
|
||
|
+impl<T> BufRead for Cursor<T> where T: AsRef<[u8]> {
|
||
|
+ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() }
|
||
|
fn consume(&mut self, amt: usize) { self.pos += amt as u64; }
|
||
|
}
|
||
|
|
||
|
@@ -264,6 +261,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result<us
|
||
|
Ok(amt)
|
||
|
}
|
||
|
|
||
|
+#[cfg(feature="collections")]
|
||
|
fn slice_write_vectored(
|
||
|
pos_mut: &mut u64,
|
||
|
slice: &mut [u8],
|
||
|
@@ -282,6 +280,7 @@ fn slice_write_vectored(
|
||
|
}
|
||
|
|
||
|
// Resizing write implementation
|
||
|
+#[cfg(feature="collections")]
|
||
|
fn vec_write(pos_mut: &mut u64, vec: &mut Vec<u8>, buf: &[u8]) -> io::Result<usize> {
|
||
|
let pos: usize = (*pos_mut).try_into().map_err(|_| {
|
||
|
Error::new(ErrorKind::InvalidInput,
|
||
|
@@ -308,6 +307,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec<u8>, buf: &[u8]) -> io::Result<usi
|
||
|
Ok(buf.len())
|
||
|
}
|
||
|
|
||
|
+#[cfg(feature="collections")]
|
||
|
fn vec_write_vectored(
|
||
|
pos_mut: &mut u64,
|
||
|
vec: &mut Vec<u8>,
|
||
|
@@ -321,13 +321,13 @@ fn vec_write_vectored(
|
||
|
Ok(nwritten)
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl Write for Cursor<&mut [u8]> {
|
||
|
#[inline]
|
||
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||
|
slice_write(&mut self.pos, self.inner, buf)
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
|
||
|
slice_write_vectored(&mut self.pos, self.inner, bufs)
|
||
|
@@ -336,12 +336,13 @@ impl Write for Cursor<&mut [u8]> {
|
||
|
fn flush(&mut self) -> io::Result<()> { Ok(()) }
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "cursor_mut_vec", since = "1.25.0")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl Write for Cursor<&mut Vec<u8>> {
|
||
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||
|
vec_write(&mut self.pos, self.inner, buf)
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
|
||
|
vec_write_vectored(&mut self.pos, self.inner, bufs)
|
||
|
}
|
||
|
@@ -349,12 +350,13 @@ impl Write for Cursor<&mut Vec<u8>> {
|
||
|
fn flush(&mut self) -> io::Result<()> { Ok(()) }
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature = "collections")]
|
||
|
impl Write for Cursor<Vec<u8>> {
|
||
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||
|
vec_write(&mut self.pos, &mut self.inner, buf)
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
|
||
|
vec_write_vectored(&mut self.pos, &mut self.inner, bufs)
|
||
|
}
|
||
|
@@ -362,13 +364,14 @@ impl Write for Cursor<Vec<u8>> {
|
||
|
fn flush(&mut self) -> io::Result<()> { Ok(()) }
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "cursor_box_slice", since = "1.5.0")]
|
||
|
-impl Write for Cursor<Box<[u8]>> {
|
||
|
+#[cfg(feature = "alloc")]
|
||
|
+impl Write for Cursor<::alloc::boxed::Box<[u8]>> {
|
||
|
#[inline]
|
||
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||
|
slice_write(&mut self.pos, &mut self.inner, buf)
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
|
||
|
slice_write_vectored(&mut self.pos, &mut self.inner, bufs)
|
||
|
diff --git a/error.rs b/error.rs
|
||
|
index 614b791..e4ce8b5 100644
|
||
|
--- a/error.rs
|
||
|
+++ b/error.rs
|
||
|
@@ -1,8 +1,13 @@
|
||
|
-use crate::error;
|
||
|
-use crate::fmt;
|
||
|
-use crate::result;
|
||
|
-use crate::sys;
|
||
|
-use crate::convert::From;
|
||
|
+#[cfg(feature="alloc")] use alloc::boxed::Box;
|
||
|
+#[cfg(not(feature="alloc"))] use ::FakeBox as Box;
|
||
|
+use core::convert::Into;
|
||
|
+use core::fmt;
|
||
|
+use core::marker::{Send, Sync};
|
||
|
+use core::option::Option::{self, Some, None};
|
||
|
+use core::result;
|
||
|
+#[cfg(feature="collections")] use collections::string::String;
|
||
|
+#[cfg(not(feature="collections"))] use ::ErrorString as String;
|
||
|
+use core::convert::From;
|
||
|
|
||
|
/// A specialized [`Result`](../result/enum.Result.html) type for I/O
|
||
|
/// operations.
|
||
|
@@ -38,7 +43,6 @@ use crate::convert::From;
|
||
|
/// Ok(buffer)
|
||
|
/// }
|
||
|
/// ```
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub type Result<T> = result::Result<T, Error>;
|
||
|
|
||
|
/// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and
|
||
|
@@ -52,12 +56,10 @@ pub type Result<T> = result::Result<T, Error>;
|
||
|
/// [`Write`]: ../io/trait.Write.html
|
||
|
/// [`Seek`]: ../io/trait.Seek.html
|
||
|
/// [`ErrorKind`]: enum.ErrorKind.html
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub struct Error {
|
||
|
repr: Repr,
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl fmt::Debug for Error {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||
|
fmt::Debug::fmt(&self.repr, f)
|
||
|
@@ -67,13 +69,16 @@ impl fmt::Debug for Error {
|
||
|
enum Repr {
|
||
|
Os(i32),
|
||
|
Simple(ErrorKind),
|
||
|
+ #[cfg(feature="alloc")]
|
||
|
Custom(Box<Custom>),
|
||
|
+ #[cfg(not(feature="alloc"))]
|
||
|
+ Custom(Custom),
|
||
|
}
|
||
|
|
||
|
#[derive(Debug)]
|
||
|
struct Custom {
|
||
|
kind: ErrorKind,
|
||
|
- error: Box<dyn error::Error+Send+Sync>,
|
||
|
+ error: String,
|
||
|
}
|
||
|
|
||
|
/// A list specifying general categories of I/O error.
|
||
|
@@ -85,48 +90,35 @@ struct Custom {
|
||
|
///
|
||
|
/// [`io::Error`]: struct.Error.html
|
||
|
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
#[allow(deprecated)]
|
||
|
#[non_exhaustive]
|
||
|
pub enum ErrorKind {
|
||
|
/// An entity was not found, often a file.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
NotFound,
|
||
|
/// The operation lacked the necessary privileges to complete.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
PermissionDenied,
|
||
|
/// The connection was refused by the remote server.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
ConnectionRefused,
|
||
|
/// The connection was reset by the remote server.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
ConnectionReset,
|
||
|
/// The connection was aborted (terminated) by the remote server.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
ConnectionAborted,
|
||
|
/// The network operation failed because it was not connected yet.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
NotConnected,
|
||
|
/// A socket address could not be bound because the address is already in
|
||
|
/// use elsewhere.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
AddrInUse,
|
||
|
/// A nonexistent interface was requested or the requested address was not
|
||
|
/// local.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
AddrNotAvailable,
|
||
|
/// The operation failed because a pipe was closed.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
BrokenPipe,
|
||
|
/// An entity already exists, often a file.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
AlreadyExists,
|
||
|
/// The operation needs to block to complete, but the blocking operation was
|
||
|
/// requested to not occur.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
WouldBlock,
|
||
|
/// A parameter was incorrect.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
InvalidInput,
|
||
|
/// Data not valid for the operation were encountered.
|
||
|
///
|
||
|
@@ -138,10 +130,8 @@ pub enum ErrorKind {
|
||
|
/// `InvalidData` if the file's contents are not valid UTF-8.
|
||
|
///
|
||
|
/// [`InvalidInput`]: #variant.InvalidInput
|
||
|
- #[stable(feature = "io_invalid_data", since = "1.2.0")]
|
||
|
InvalidData,
|
||
|
/// The I/O operation's timeout expired, causing it to be canceled.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
TimedOut,
|
||
|
/// An error returned when an operation could not be completed because a
|
||
|
/// call to [`write`] returned [`Ok(0)`].
|
||
|
@@ -152,15 +142,12 @@ pub enum ErrorKind {
|
||
|
///
|
||
|
/// [`write`]: ../../std/io/trait.Write.html#tymethod.write
|
||
|
/// [`Ok(0)`]: ../../std/io/type.Result.html
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
WriteZero,
|
||
|
/// This operation was interrupted.
|
||
|
///
|
||
|
/// Interrupted operations can typically be retried.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
Interrupted,
|
||
|
/// Any I/O error not part of this list.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
Other,
|
||
|
|
||
|
/// An error returned when an operation could not be completed because an
|
||
|
@@ -169,7 +156,6 @@ pub enum ErrorKind {
|
||
|
/// This typically means that an operation could only succeed if it read a
|
||
|
/// particular number of bytes but only a smaller number of bytes could be
|
||
|
/// read.
|
||
|
- #[stable(feature = "read_exact", since = "1.6.0")]
|
||
|
UnexpectedEof,
|
||
|
}
|
||
|
|
||
|
@@ -200,7 +186,6 @@ impl ErrorKind {
|
||
|
|
||
|
/// Intended for use for errors not exposed to the user, where allocating onto
|
||
|
/// the heap (for normal construction via Error::new) is too costly.
|
||
|
-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")]
|
||
|
impl From<ErrorKind> for Error {
|
||
|
/// Converts an [`ErrorKind`] into an [`Error`].
|
||
|
///
|
||
|
@@ -245,14 +230,13 @@ impl Error {
|
||
|
/// // errors can also be created from other errors
|
||
|
/// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error);
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn new<E>(kind: ErrorKind, error: E) -> Error
|
||
|
- where E: Into<Box<dyn error::Error+Send+Sync>>
|
||
|
+ where E: Into<String>
|
||
|
{
|
||
|
Self::_new(kind, error.into())
|
||
|
}
|
||
|
|
||
|
- fn _new(kind: ErrorKind, error: Box<dyn error::Error+Send+Sync>) -> Error {
|
||
|
+ fn _new(kind: ErrorKind, error: String) -> Error {
|
||
|
Error {
|
||
|
repr: Repr::Custom(Box::new(Custom {
|
||
|
kind,
|
||
|
@@ -261,24 +245,6 @@ impl Error {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- /// Returns an error representing the last OS error which occurred.
|
||
|
- ///
|
||
|
- /// This function reads the value of `errno` for the target platform (e.g.
|
||
|
- /// `GetLastError` on Windows) and will return a corresponding instance of
|
||
|
- /// `Error` for the error code.
|
||
|
- ///
|
||
|
- /// # Examples
|
||
|
- ///
|
||
|
- /// ```
|
||
|
- /// use std::io::Error;
|
||
|
- ///
|
||
|
- /// println!("last OS error: {:?}", Error::last_os_error());
|
||
|
- /// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
- pub fn last_os_error() -> Error {
|
||
|
- Error::from_raw_os_error(sys::os::errno() as i32)
|
||
|
- }
|
||
|
-
|
||
|
/// Creates a new instance of an `Error` from a particular OS error code.
|
||
|
///
|
||
|
/// # Examples
|
||
|
@@ -304,7 +270,6 @@ impl Error {
|
||
|
/// assert_eq!(error.kind(), io::ErrorKind::InvalidInput);
|
||
|
/// # }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn from_raw_os_error(code: i32) -> Error {
|
||
|
Error { repr: Repr::Os(code) }
|
||
|
}
|
||
|
@@ -335,7 +300,6 @@ impl Error {
|
||
|
/// print_os_error(&Error::new(ErrorKind::Other, "oh no!"));
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn raw_os_error(&self) -> Option<i32> {
|
||
|
match self.repr {
|
||
|
Repr::Os(i) => Some(i),
|
||
|
@@ -369,12 +333,11 @@ impl Error {
|
||
|
/// print_error(&Error::new(ErrorKind::Other, "oh no!"));
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "io_error_inner", since = "1.3.0")]
|
||
|
- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> {
|
||
|
+ pub fn get_ref(&self) -> Option<&String> {
|
||
|
match self.repr {
|
||
|
Repr::Os(..) => None,
|
||
|
Repr::Simple(..) => None,
|
||
|
- Repr::Custom(ref c) => Some(&*c.error),
|
||
|
+ Repr::Custom(ref c) => Some(&c.error),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@@ -440,12 +403,11 @@ impl Error {
|
||
|
/// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new())));
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "io_error_inner", since = "1.3.0")]
|
||
|
- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> {
|
||
|
+ pub fn get_mut(&mut self) -> Option<&mut String> {
|
||
|
match self.repr {
|
||
|
Repr::Os(..) => None,
|
||
|
Repr::Simple(..) => None,
|
||
|
- Repr::Custom(ref mut c) => Some(&mut *c.error),
|
||
|
+ Repr::Custom(ref mut c) => Some(&mut c.error),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@@ -474,8 +436,7 @@ impl Error {
|
||
|
/// print_error(Error::new(ErrorKind::Other, "oh no!"));
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "io_error_inner", since = "1.3.0")]
|
||
|
- pub fn into_inner(self) -> Option<Box<dyn error::Error+Send+Sync>> {
|
||
|
+ pub fn into_inner(self) -> Option<String> {
|
||
|
match self.repr {
|
||
|
Repr::Os(..) => None,
|
||
|
Repr::Simple(..) => None,
|
||
|
@@ -501,10 +462,9 @@ impl Error {
|
||
|
/// print_error(Error::new(ErrorKind::AddrInUse, "oh no!"));
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn kind(&self) -> ErrorKind {
|
||
|
match self.repr {
|
||
|
- Repr::Os(code) => sys::decode_error_kind(code),
|
||
|
+ Repr::Os(_code) => ErrorKind::Other,
|
||
|
Repr::Custom(ref c) => c.kind,
|
||
|
Repr::Simple(kind) => kind,
|
||
|
}
|
||
|
@@ -516,22 +476,18 @@ impl fmt::Debug for Repr {
|
||
|
match *self {
|
||
|
Repr::Os(code) =>
|
||
|
fmt.debug_struct("Os")
|
||
|
- .field("code", &code)
|
||
|
- .field("kind", &sys::decode_error_kind(code))
|
||
|
- .field("message", &sys::os::error_string(code)).finish(),
|
||
|
+ .field("code", &code).finish(),
|
||
|
Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt),
|
||
|
Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl fmt::Display for Error {
|
||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||
|
match self.repr {
|
||
|
Repr::Os(code) => {
|
||
|
- let detail = sys::os::error_string(code);
|
||
|
- write!(fmt, "{} (os error {})", detail, code)
|
||
|
+ write!(fmt, "os error {}", code)
|
||
|
}
|
||
|
Repr::Custom(ref c) => c.error.fmt(fmt),
|
||
|
Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()),
|
||
|
@@ -539,33 +495,6 @@ impl fmt::Display for Error {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
-impl error::Error for Error {
|
||
|
- fn description(&self) -> &str {
|
||
|
- match self.repr {
|
||
|
- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(),
|
||
|
- Repr::Custom(ref c) => c.error.description(),
|
||
|
- }
|
||
|
- }
|
||
|
-
|
||
|
- #[allow(deprecated)]
|
||
|
- fn cause(&self) -> Option<&dyn error::Error> {
|
||
|
- match self.repr {
|
||
|
- Repr::Os(..) => None,
|
||
|
- Repr::Simple(..) => None,
|
||
|
- Repr::Custom(ref c) => c.error.cause(),
|
||
|
- }
|
||
|
- }
|
||
|
-
|
||
|
- fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||
|
- match self.repr {
|
||
|
- Repr::Os(..) => None,
|
||
|
- Repr::Simple(..) => None,
|
||
|
- Repr::Custom(ref c) => c.error.source(),
|
||
|
- }
|
||
|
- }
|
||
|
-}
|
||
|
-
|
||
|
fn _assert_error_is_sync_send() {
|
||
|
fn _is_sync_send<T: Sync+Send>() {}
|
||
|
_is_sync_send::<Error>();
|
||
|
diff --git a/impls.rs b/impls.rs
|
||
|
index b286e40..7472d9c 100644
|
||
|
--- a/impls.rs
|
||
|
+++ b/impls.rs
|
||
|
@@ -1,19 +1,22 @@
|
||
|
-use crate::cmp;
|
||
|
-use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut,
|
||
|
- IoVec};
|
||
|
-use crate::fmt;
|
||
|
-use crate::mem;
|
||
|
+#[cfg(feature="alloc")] use alloc::boxed::Box;
|
||
|
+use core::cmp;
|
||
|
+use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind};
|
||
|
+#[cfg(feature="collections")] use crate::io::{BufRead, IoVecMut, IoVec};
|
||
|
+use core::fmt;
|
||
|
+use core::mem;
|
||
|
+#[cfg(feature="collections")] use collections::string::String;
|
||
|
+#[cfg(feature="collections")] use collections::vec::Vec;
|
||
|
|
||
|
// =============================================================================
|
||
|
// Forwarding implementations
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<R: Read + ?Sized> Read for &mut R {
|
||
|
#[inline]
|
||
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||
|
(**self).read(buf)
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result<usize> {
|
||
|
(**self).read_vectored(bufs)
|
||
|
@@ -24,11 +27,13 @@ impl<R: Read + ?Sized> Read for &mut R {
|
||
|
(**self).initializer()
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
|
||
|
(**self).read_to_end(buf)
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
|
||
|
(**self).read_to_string(buf)
|
||
|
@@ -39,11 +44,11 @@ impl<R: Read + ?Sized> Read for &mut R {
|
||
|
(**self).read_exact(buf)
|
||
|
}
|
||
|
}
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<W: Write + ?Sized> Write for &mut W {
|
||
|
#[inline]
|
||
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (**self).write(buf) }
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
|
||
|
(**self).write_vectored(bufs)
|
||
|
@@ -62,12 +67,11 @@ impl<W: Write + ?Sized> Write for &mut W {
|
||
|
(**self).write_fmt(fmt)
|
||
|
}
|
||
|
}
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<S: Seek + ?Sized> Seek for &mut S {
|
||
|
#[inline]
|
||
|
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { (**self).seek(pos) }
|
||
|
}
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl<B: BufRead + ?Sized> BufRead for &mut B {
|
||
|
#[inline]
|
||
|
fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() }
|
||
|
@@ -86,13 +90,14 @@ impl<B: BufRead + ?Sized> BufRead for &mut B {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature="alloc")]
|
||
|
impl<R: Read + ?Sized> Read for Box<R> {
|
||
|
#[inline]
|
||
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||
|
(**self).read(buf)
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result<usize> {
|
||
|
(**self).read_vectored(bufs)
|
||
|
@@ -103,11 +108,13 @@ impl<R: Read + ?Sized> Read for Box<R> {
|
||
|
(**self).initializer()
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
|
||
|
(**self).read_to_end(buf)
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
|
||
|
(**self).read_to_string(buf)
|
||
|
@@ -118,11 +125,12 @@ impl<R: Read + ?Sized> Read for Box<R> {
|
||
|
(**self).read_exact(buf)
|
||
|
}
|
||
|
}
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature="alloc")]
|
||
|
impl<W: Write + ?Sized> Write for Box<W> {
|
||
|
#[inline]
|
||
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (**self).write(buf) }
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
|
||
|
(**self).write_vectored(bufs)
|
||
|
@@ -141,12 +149,12 @@ impl<W: Write + ?Sized> Write for Box<W> {
|
||
|
(**self).write_fmt(fmt)
|
||
|
}
|
||
|
}
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature="alloc")]
|
||
|
impl<S: Seek + ?Sized> Seek for Box<S> {
|
||
|
#[inline]
|
||
|
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { (**self).seek(pos) }
|
||
|
}
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl<B: BufRead + ?Sized> BufRead for Box<B> {
|
||
|
#[inline]
|
||
|
fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() }
|
||
|
@@ -186,7 +194,6 @@ impl Write for Box<dyn (::realstd::io::Write) + Send> {
|
||
|
///
|
||
|
/// Note that reading updates the slice to point to the yet unread part.
|
||
|
/// The slice will be empty when EOF is reached.
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl Read for &[u8] {
|
||
|
#[inline]
|
||
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||
|
@@ -206,6 +213,7 @@ impl Read for &[u8] {
|
||
|
Ok(amt)
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result<usize> {
|
||
|
let mut nread = 0;
|
||
|
@@ -245,6 +253,7 @@ impl Read for &[u8] {
|
||
|
Ok(())
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
|
||
|
buf.extend_from_slice(*self);
|
||
|
@@ -254,7 +263,7 @@ impl Read for &[u8] {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl BufRead for &[u8] {
|
||
|
#[inline]
|
||
|
fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) }
|
||
|
@@ -268,7 +277,6 @@ impl BufRead for &[u8] {
|
||
|
///
|
||
|
/// Note that writing updates the slice to point to the yet unwritten part.
|
||
|
/// The slice will be empty when it has been completely overwritten.
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl Write for &mut [u8] {
|
||
|
#[inline]
|
||
|
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
||
|
@@ -279,6 +287,7 @@ impl Write for &mut [u8] {
|
||
|
Ok(amt)
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
|
||
|
let mut nwritten = 0;
|
||
|
@@ -307,7 +316,7 @@ impl Write for &mut [u8] {
|
||
|
|
||
|
/// Write is implemented for `Vec<u8>` by appending to the vector.
|
||
|
/// The vector will grow as needed.
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl Write for Vec<u8> {
|
||
|
#[inline]
|
||
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||
|
@@ -315,6 +324,7 @@ impl Write for Vec<u8> {
|
||
|
Ok(buf.len())
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
|
||
|
let len = bufs.iter().map(|b| b.len()).sum();
|
||
|
diff --git a/mod.rs b/mod.rs
|
||
|
index 1a2152a..85652f4 100644
|
||
|
--- a/mod.rs
|
||
|
+++ b/mod.rs
|
||
|
@@ -257,50 +257,38 @@
|
||
|
//! [`Result`]: ../result/enum.Result.html
|
||
|
//! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap
|
||
|
|
||
|
-#![stable(feature = "rust1", since = "1.0.0")]
|
||
|
-
|
||
|
-use crate::cmp;
|
||
|
-use crate::fmt;
|
||
|
-use crate::slice;
|
||
|
-use crate::str;
|
||
|
-use crate::memchr;
|
||
|
-use crate::ops::{Deref, DerefMut};
|
||
|
-use crate::ptr;
|
||
|
-use crate::sys;
|
||
|
-
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
-pub use self::buffered::{BufReader, BufWriter, LineWriter};
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
-pub use self::buffered::IntoInnerError;
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+use core::cmp;
|
||
|
+use core::fmt;
|
||
|
+#[cfg(feature="collections")] use collections::string::String;
|
||
|
+use core::str;
|
||
|
+#[cfg(feature="collections")] use collections::vec::Vec;
|
||
|
+#[cfg(not(core_memchr))]
|
||
|
+mod memchr;
|
||
|
+#[cfg(all(feature="collections",core_memchr))]
|
||
|
+use core::slice::memchr;
|
||
|
+#[cfg(feature="collections")] use core::ops::{Deref, DerefMut};
|
||
|
+use core::ptr;
|
||
|
+use core::slice;
|
||
|
+
|
||
|
+#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter};
|
||
|
+#[cfg(feature="collections")] pub use self::buffered::IntoInnerError;
|
||
|
pub use self::cursor::Cursor;
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub use self::error::{Result, Error, ErrorKind};
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat};
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr};
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
-pub use self::stdio::{StdoutLock, StderrLock, StdinLock};
|
||
|
-#[unstable(feature = "print_internals", issue = "0")]
|
||
|
-pub use self::stdio::{_print, _eprint};
|
||
|
-#[unstable(feature = "libstd_io_internals", issue = "42788")]
|
||
|
-#[doc(no_inline, hidden)]
|
||
|
-pub use self::stdio::{set_panic, set_print};
|
||
|
|
||
|
pub mod prelude;
|
||
|
-mod buffered;
|
||
|
+#[cfg(feature="collections")] mod buffered;
|
||
|
mod cursor;
|
||
|
mod error;
|
||
|
mod impls;
|
||
|
-mod lazy;
|
||
|
mod util;
|
||
|
-mod stdio;
|
||
|
|
||
|
-const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
|
||
|
+const DEFAULT_BUF_SIZE: usize = 8 * 1024;
|
||
|
|
||
|
+#[cfg(feature="collections")]
|
||
|
struct Guard<'a> { buf: &'a mut Vec<u8>, len: usize }
|
||
|
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl Drop for Guard<'_> {
|
||
|
fn drop(&mut self) {
|
||
|
unsafe { self.buf.set_len(self.len); }
|
||
|
@@ -325,6 +313,7 @@ impl Drop for Guard<'_> {
|
||
|
// 2. We're passing a raw buffer to the function `f`, and it is expected that
|
||
|
// the function only *appends* bytes to the buffer. We'll get undefined
|
||
|
// behavior if existing bytes are overwritten to have non-UTF-8 data.
|
||
|
+#[cfg(feature="collections")]
|
||
|
fn append_to_string<F>(buf: &mut String, f: F) -> Result<usize>
|
||
|
where F: FnOnce(&mut Vec<u8>) -> Result<usize>
|
||
|
{
|
||
|
@@ -352,10 +341,12 @@ fn append_to_string<F>(buf: &mut String, f: F) -> Result<usize>
|
||
|
//
|
||
|
// Because we're extending the buffer with uninitialized data for trusted
|
||
|
// readers, we need to make sure to truncate that if any of this panics.
|
||
|
+#[cfg(feature="collections")]
|
||
|
fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize> {
|
||
|
read_to_end_with_reservation(r, buf, 32)
|
||
|
}
|
||
|
|
||
|
+#[cfg(feature="collections")]
|
||
|
fn read_to_end_with_reservation<R: Read + ?Sized>(r: &mut R,
|
||
|
buf: &mut Vec<u8>,
|
||
|
reservation_size: usize) -> Result<usize>
|
||
|
@@ -390,6 +381,7 @@ fn read_to_end_with_reservation<R: Read + ?Sized>(r: &mut R,
|
||
|
ret
|
||
|
}
|
||
|
|
||
|
+#[cfg(feature="collections")]
|
||
|
pub(crate) fn default_read_vectored<F>(read: F, bufs: &mut [IoVecMut<'_>]) -> Result<usize>
|
||
|
where
|
||
|
F: FnOnce(&mut [u8]) -> Result<usize>
|
||
|
@@ -401,6 +393,7 @@ where
|
||
|
read(buf)
|
||
|
}
|
||
|
|
||
|
+#[cfg(feature="collections")]
|
||
|
pub(crate) fn default_write_vectored<F>(write: F, bufs: &[IoVec<'_>]) -> Result<usize>
|
||
|
where
|
||
|
F: FnOnce(&[u8]) -> Result<usize>
|
||
|
@@ -484,7 +477,6 @@ where
|
||
|
/// [`BufReader`]: struct.BufReader.html
|
||
|
/// [`&str`]: ../../std/primitive.str.html
|
||
|
/// [slice]: ../../std/primitive.slice.html
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
#[doc(spotlight)]
|
||
|
pub trait Read {
|
||
|
/// Pull some bytes from this source into the specified buffer, returning
|
||
|
@@ -541,7 +533,6 @@ pub trait Read {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
|
||
|
|
||
|
/// Like `read`, except that it reads into a slice of buffers.
|
||
|
@@ -552,7 +543,7 @@ pub trait Read {
|
||
|
///
|
||
|
/// The default implementation calls `read` with either the first nonempty
|
||
|
/// buffer provided, or an empty one if none exists.
|
||
|
- #[unstable(feature = "iovec", issue = "58452")]
|
||
|
+ #[cfg(feature="collections")]
|
||
|
fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result<usize> {
|
||
|
default_read_vectored(|b| self.read(b), bufs)
|
||
|
}
|
||
|
@@ -579,7 +570,6 @@ pub trait Read {
|
||
|
///
|
||
|
/// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop
|
||
|
/// [`Initializer`]: ../../std/io/struct.Initializer.html
|
||
|
- #[unstable(feature = "read_initializer", issue = "42788")]
|
||
|
#[inline]
|
||
|
unsafe fn initializer(&self) -> Initializer {
|
||
|
Initializer::zeroing()
|
||
|
@@ -632,7 +622,7 @@ pub trait Read {
|
||
|
/// file.)
|
||
|
///
|
||
|
/// [`std::fs::read`]: ../fs/fn.read.html
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+ #[cfg(feature="collections")]
|
||
|
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> {
|
||
|
read_to_end(self, buf)
|
||
|
}
|
||
|
@@ -675,7 +665,7 @@ pub trait Read {
|
||
|
/// reading from a file.)
|
||
|
///
|
||
|
/// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+ #[cfg(feature="collections")]
|
||
|
fn read_to_string(&mut self, buf: &mut String) -> Result<usize> {
|
||
|
// Note that we do *not* call `.read_to_end()` here. We are passing
|
||
|
// `&mut Vec<u8>` (the raw contents of `buf`) into the `read_to_end`
|
||
|
@@ -738,7 +728,6 @@ pub trait Read {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "read_exact", since = "1.6.0")]
|
||
|
fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> {
|
||
|
while !buf.is_empty() {
|
||
|
match self.read(buf) {
|
||
|
@@ -790,7 +779,6 @@ pub trait Read {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
|
||
|
|
||
|
/// Transforms this `Read` instance to an [`Iterator`] over its bytes.
|
||
|
@@ -827,7 +815,6 @@ pub trait Read {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn bytes(self) -> Bytes<Self> where Self: Sized {
|
||
|
Bytes { inner: self }
|
||
|
}
|
||
|
@@ -862,7 +849,6 @@ pub trait Read {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn chain<R: Read>(self, next: R) -> Chain<Self, R> where Self: Sized {
|
||
|
Chain { first: self, second: next, done_first: false }
|
||
|
}
|
||
|
@@ -898,42 +884,77 @@ pub trait Read {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn take(self, limit: u64) -> Take<Self> where Self: Sized {
|
||
|
Take { inner: self, limit: limit }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
+#[cfg(feature="collections")]
|
||
|
+pub struct IoVecBuffer<'a>(&'a [u8]);
|
||
|
+
|
||
|
+#[cfg(feature="collections")]
|
||
|
+impl<'a> IoVecBuffer<'a> {
|
||
|
+ #[inline]
|
||
|
+ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> {
|
||
|
+ IoVecBuffer(buf)
|
||
|
+ }
|
||
|
+
|
||
|
+ #[inline]
|
||
|
+ pub fn as_slice(&self) -> &[u8] {
|
||
|
+ self.0
|
||
|
+ }
|
||
|
+}
|
||
|
+#[cfg(feature="collections")]
|
||
|
+pub struct IoVecMutBuffer<'a>(&'a mut [u8]);
|
||
|
+
|
||
|
+#[cfg(feature="collections")]
|
||
|
+impl<'a> IoVecMutBuffer<'a> {
|
||
|
+ #[inline]
|
||
|
+ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> {
|
||
|
+ IoVecMutBuffer(buf)
|
||
|
+ }
|
||
|
+
|
||
|
+ #[inline]
|
||
|
+ pub fn as_slice(&self) -> &[u8] {
|
||
|
+ self.0
|
||
|
+ }
|
||
|
+
|
||
|
+ #[inline]
|
||
|
+ pub fn as_mut_slice(&mut self) -> &mut [u8] {
|
||
|
+ self.0
|
||
|
+ }
|
||
|
+}
|
||
|
+
|
||
|
/// A buffer type used with `Read::read_vectored`.
|
||
|
///
|
||
|
/// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be
|
||
|
/// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on
|
||
|
/// Windows.
|
||
|
-#[unstable(feature = "iovec", issue = "58452")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
#[repr(transparent)]
|
||
|
-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>);
|
||
|
+pub struct IoVecMut<'a>(IoVecMutBuffer<'a>);
|
||
|
|
||
|
-#[unstable(feature = "iovec", issue = "58452")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl<'a> fmt::Debug for IoVecMut<'a> {
|
||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||
|
fmt::Debug::fmt(self.0.as_slice(), fmt)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl<'a> IoVecMut<'a> {
|
||
|
/// Creates a new `IoVecMut` wrapping a byte slice.
|
||
|
///
|
||
|
/// # Panics
|
||
|
///
|
||
|
/// Panics on Windows if the slice is larger than 4GB.
|
||
|
- #[unstable(feature = "iovec", issue = "58452")]
|
||
|
#[inline]
|
||
|
pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> {
|
||
|
- IoVecMut(sys::io::IoVecMut::new(buf))
|
||
|
+ IoVecMut(IoVecMutBuffer::new(buf))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[unstable(feature = "iovec", issue = "58452")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl<'a> Deref for IoVecMut<'a> {
|
||
|
type Target = [u8];
|
||
|
|
||
|
@@ -943,7 +964,7 @@ impl<'a> Deref for IoVecMut<'a> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[unstable(feature = "iovec", issue = "58452")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl<'a> DerefMut for IoVecMut<'a> {
|
||
|
#[inline]
|
||
|
fn deref_mut(&mut self) -> &mut [u8] {
|
||
|
@@ -956,31 +977,31 @@ impl<'a> DerefMut for IoVecMut<'a> {
|
||
|
/// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be
|
||
|
/// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on
|
||
|
/// Windows.
|
||
|
-#[unstable(feature = "iovec", issue = "58452")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
#[repr(transparent)]
|
||
|
-pub struct IoVec<'a>(sys::io::IoVec<'a>);
|
||
|
+pub struct IoVec<'a>(IoVecBuffer<'a>);
|
||
|
|
||
|
-#[unstable(feature = "iovec", issue = "58452")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl<'a> fmt::Debug for IoVec<'a> {
|
||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||
|
fmt::Debug::fmt(self.0.as_slice(), fmt)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl<'a> IoVec<'a> {
|
||
|
/// Creates a new `IoVec` wrapping a byte slice.
|
||
|
///
|
||
|
/// # Panics
|
||
|
///
|
||
|
/// Panics on Windows if the slice is larger than 4GB.
|
||
|
- #[unstable(feature = "iovec", issue = "58452")]
|
||
|
#[inline]
|
||
|
pub fn new(buf: &'a [u8]) -> IoVec<'a> {
|
||
|
- IoVec(sys::io::IoVec::new(buf))
|
||
|
+ IoVec(IoVecBuffer::new(buf))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[unstable(feature = "iovec", issue = "58452")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl<'a> Deref for IoVec<'a> {
|
||
|
type Target = [u8];
|
||
|
|
||
|
@@ -991,13 +1012,11 @@ impl<'a> Deref for IoVec<'a> {
|
||
|
}
|
||
|
|
||
|
/// A type used to conditionally initialize buffers passed to `Read` methods.
|
||
|
-#[unstable(feature = "read_initializer", issue = "42788")]
|
||
|
#[derive(Debug)]
|
||
|
pub struct Initializer(bool);
|
||
|
|
||
|
impl Initializer {
|
||
|
/// Returns a new `Initializer` which will zero out buffers.
|
||
|
- #[unstable(feature = "read_initializer", issue = "42788")]
|
||
|
#[inline]
|
||
|
pub fn zeroing() -> Initializer {
|
||
|
Initializer(true)
|
||
|
@@ -1011,21 +1030,18 @@ impl Initializer {
|
||
|
/// read from buffers passed to `Read` methods, and that the return value of
|
||
|
/// the method accurately reflects the number of bytes that have been
|
||
|
/// written to the head of the buffer.
|
||
|
- #[unstable(feature = "read_initializer", issue = "42788")]
|
||
|
#[inline]
|
||
|
pub unsafe fn nop() -> Initializer {
|
||
|
Initializer(false)
|
||
|
}
|
||
|
|
||
|
/// Indicates if a buffer should be initialized.
|
||
|
- #[unstable(feature = "read_initializer", issue = "42788")]
|
||
|
#[inline]
|
||
|
pub fn should_initialize(&self) -> bool {
|
||
|
self.0
|
||
|
}
|
||
|
|
||
|
/// Initializes a buffer if necessary.
|
||
|
- #[unstable(feature = "read_initializer", issue = "42788")]
|
||
|
#[inline]
|
||
|
pub fn initialize(&self, buf: &mut [u8]) {
|
||
|
if self.should_initialize() {
|
||
|
@@ -1068,7 +1084,6 @@ impl Initializer {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
#[doc(spotlight)]
|
||
|
pub trait Write {
|
||
|
/// Write a buffer into this writer, returning how many bytes were written.
|
||
|
@@ -1117,7 +1132,6 @@ pub trait Write {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn write(&mut self, buf: &[u8]) -> Result<usize>;
|
||
|
|
||
|
/// Like `write`, except that it writes from a slice of buffers.
|
||
|
@@ -1128,7 +1142,7 @@ pub trait Write {
|
||
|
///
|
||
|
/// The default implementation calls `write` with either the first nonempty
|
||
|
/// buffer provided, or an empty one if none exists.
|
||
|
- #[unstable(feature = "iovec", issue = "58452")]
|
||
|
+ #[cfg(feature="collections")]
|
||
|
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result<usize> {
|
||
|
default_write_vectored(|b| self.write(b), bufs)
|
||
|
}
|
||
|
@@ -1156,7 +1170,6 @@ pub trait Write {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn flush(&mut self) -> Result<()>;
|
||
|
|
||
|
/// Attempts to write an entire buffer into this writer.
|
||
|
@@ -1189,7 +1202,6 @@ pub trait Write {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn write_all(&mut self, mut buf: &[u8]) -> Result<()> {
|
||
|
while !buf.is_empty() {
|
||
|
match self.write(buf) {
|
||
|
@@ -1241,7 +1253,6 @@ pub trait Write {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> {
|
||
|
// Create a shim which translates a Write to a fmt::Write and saves
|
||
|
// off I/O errors. instead of discarding them
|
||
|
@@ -1297,7 +1308,6 @@ pub trait Write {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
|
||
|
}
|
||
|
|
||
|
@@ -1327,7 +1337,6 @@ pub trait Write {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub trait Seek {
|
||
|
/// Seek to an offset, in bytes, in a stream.
|
||
|
///
|
||
|
@@ -1343,7 +1352,6 @@ pub trait Seek {
|
||
|
/// Seeking to a negative offset is considered an error.
|
||
|
///
|
||
|
/// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn seek(&mut self, pos: SeekFrom) -> Result<u64>;
|
||
|
}
|
||
|
|
||
|
@@ -1353,29 +1361,26 @@ pub trait Seek {
|
||
|
///
|
||
|
/// [`Seek`]: trait.Seek.html
|
||
|
#[derive(Copy, PartialEq, Eq, Clone, Debug)]
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub enum SeekFrom {
|
||
|
/// Sets the offset to the provided number of bytes.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
- Start(#[stable(feature = "rust1", since = "1.0.0")] u64),
|
||
|
+ Start(u64),
|
||
|
|
||
|
/// Sets the offset to the size of this object plus the specified number of
|
||
|
/// bytes.
|
||
|
///
|
||
|
/// It is possible to seek beyond the end of an object, but it's an error to
|
||
|
/// seek before byte 0.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
- End(#[stable(feature = "rust1", since = "1.0.0")] i64),
|
||
|
+ End(i64),
|
||
|
|
||
|
/// Sets the offset to the current position plus the specified number of
|
||
|
/// bytes.
|
||
|
///
|
||
|
/// It is possible to seek beyond the end of an object, but it's an error to
|
||
|
/// seek before byte 0.
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
- Current(#[stable(feature = "rust1", since = "1.0.0")] i64),
|
||
|
+ Current(i64),
|
||
|
}
|
||
|
|
||
|
+#[cfg(feature="collections")]
|
||
|
fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
|
||
|
-> Result<usize> {
|
||
|
let mut read = 0;
|
||
|
@@ -1455,7 +1460,7 @@ fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
|
||
|
/// }
|
||
|
/// ```
|
||
|
///
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
pub trait BufRead: Read {
|
||
|
/// Returns the contents of the internal buffer, filling it with more data
|
||
|
/// from the inner reader if it is empty.
|
||
|
@@ -1501,7 +1506,6 @@ pub trait BufRead: Read {
|
||
|
/// // ensure the bytes we worked with aren't returned again later
|
||
|
/// stdin.consume(length);
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn fill_buf(&mut self) -> Result<&[u8]>;
|
||
|
|
||
|
/// Tells this buffer that `amt` bytes have been consumed from the buffer,
|
||
|
@@ -1523,7 +1527,6 @@ pub trait BufRead: Read {
|
||
|
/// that method's example includes an example of `consume()`.
|
||
|
///
|
||
|
/// [`fill_buf`]: #tymethod.fill_buf
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn consume(&mut self, amt: usize);
|
||
|
|
||
|
/// Read all bytes into `buf` until the delimiter `byte` or EOF is reached.
|
||
|
@@ -1579,7 +1582,6 @@ pub trait BufRead: Read {
|
||
|
/// assert_eq!(num_bytes, 0);
|
||
|
/// assert_eq!(buf, b"");
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize> {
|
||
|
read_until(self, byte, buf)
|
||
|
}
|
||
|
@@ -1638,7 +1640,6 @@ pub trait BufRead: Read {
|
||
|
/// assert_eq!(num_bytes, 0);
|
||
|
/// assert_eq!(buf, "");
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn read_line(&mut self, buf: &mut String) -> Result<usize> {
|
||
|
// Note that we are not calling the `.read_until` method here, but
|
||
|
// rather our hardcoded implementation. For more details as to why, see
|
||
|
@@ -1679,7 +1680,6 @@ pub trait BufRead: Read {
|
||
|
/// assert_eq!(split_iter.next(), Some(b"dolor".to_vec()));
|
||
|
/// assert_eq!(split_iter.next(), None);
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn split(self, byte: u8) -> Split<Self> where Self: Sized {
|
||
|
Split { buf: self, delim: byte }
|
||
|
}
|
||
|
@@ -1718,7 +1718,6 @@ pub trait BufRead: Read {
|
||
|
/// Each line of the iterator has the same error semantics as [`BufRead::read_line`].
|
||
|
///
|
||
|
/// [`BufRead::read_line`]: trait.BufRead.html#method.read_line
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
fn lines(self) -> Lines<Self> where Self: Sized {
|
||
|
Lines { buf: self }
|
||
|
}
|
||
|
@@ -1730,7 +1729,6 @@ pub trait BufRead: Read {
|
||
|
/// Please see the documentation of [`chain`] for more details.
|
||
|
///
|
||
|
/// [`chain`]: trait.Read.html#method.chain
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub struct Chain<T, U> {
|
||
|
first: T,
|
||
|
second: U,
|
||
|
@@ -1756,7 +1754,6 @@ impl<T, U> Chain<T, U> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "more_io_inner_methods", since = "1.20.0")]
|
||
|
pub fn into_inner(self) -> (T, U) {
|
||
|
(self.first, self.second)
|
||
|
}
|
||
|
@@ -1779,7 +1776,6 @@ impl<T, U> Chain<T, U> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "more_io_inner_methods", since = "1.20.0")]
|
||
|
pub fn get_ref(&self) -> (&T, &U) {
|
||
|
(&self.first, &self.second)
|
||
|
}
|
||
|
@@ -1806,13 +1802,11 @@ impl<T, U> Chain<T, U> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "more_io_inner_methods", since = "1.20.0")]
|
||
|
pub fn get_mut(&mut self) -> (&mut T, &mut U) {
|
||
|
(&mut self.first, &mut self.second)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "std_debug", since = "1.16.0")]
|
||
|
impl<T: fmt::Debug, U: fmt::Debug> fmt::Debug for Chain<T, U> {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||
|
f.debug_struct("Chain")
|
||
|
@@ -1822,7 +1816,6 @@ impl<T: fmt::Debug, U: fmt::Debug> fmt::Debug for Chain<T, U> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<T: Read, U: Read> Read for Chain<T, U> {
|
||
|
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
|
||
|
if !self.done_first {
|
||
|
@@ -1834,6 +1827,7 @@ impl<T: Read, U: Read> Read for Chain<T, U> {
|
||
|
self.second.read(buf)
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result<usize> {
|
||
|
if !self.done_first {
|
||
|
match self.first.read_vectored(bufs)? {
|
||
|
@@ -1854,7 +1848,7 @@ impl<T: Read, U: Read> Read for Chain<T, U> {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "chain_bufread", since = "1.9.0")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
|
||
|
fn fill_buf(&mut self) -> Result<&[u8]> {
|
||
|
if !self.done_first {
|
||
|
@@ -1881,7 +1875,6 @@ impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
|
||
|
/// Please see the documentation of [`take`] for more details.
|
||
|
///
|
||
|
/// [`take`]: trait.Read.html#method.take
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
#[derive(Debug)]
|
||
|
pub struct Take<T> {
|
||
|
inner: T,
|
||
|
@@ -1916,7 +1909,6 @@ impl<T> Take<T> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn limit(&self) -> u64 { self.limit }
|
||
|
|
||
|
/// Sets the number of bytes that can be read before this instance will
|
||
|
@@ -1942,7 +1934,6 @@ impl<T> Take<T> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "take_set_limit", since = "1.27.0")]
|
||
|
pub fn set_limit(&mut self, limit: u64) {
|
||
|
self.limit = limit;
|
||
|
}
|
||
|
@@ -1967,7 +1958,6 @@ impl<T> Take<T> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "io_take_into_inner", since = "1.15.0")]
|
||
|
pub fn into_inner(self) -> T {
|
||
|
self.inner
|
||
|
}
|
||
|
@@ -1992,7 +1982,6 @@ impl<T> Take<T> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "more_io_inner_methods", since = "1.20.0")]
|
||
|
pub fn get_ref(&self) -> &T {
|
||
|
&self.inner
|
||
|
}
|
||
|
@@ -2021,13 +2010,11 @@ impl<T> Take<T> {
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
- #[stable(feature = "more_io_inner_methods", since = "1.20.0")]
|
||
|
pub fn get_mut(&mut self) -> &mut T {
|
||
|
&mut self.inner
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<T: Read> Read for Take<T> {
|
||
|
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
|
||
|
// Don't call into inner reader at all at EOF because it may still block
|
||
|
@@ -2044,15 +2031,9 @@ impl<T: Read> Read for Take<T> {
|
||
|
unsafe fn initializer(&self) -> Initializer {
|
||
|
self.inner.initializer()
|
||
|
}
|
||
|
-
|
||
|
- fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> {
|
||
|
- let reservation_size = cmp::min(self.limit, 32) as usize;
|
||
|
-
|
||
|
- read_to_end_with_reservation(self, buf, reservation_size)
|
||
|
- }
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl<T: BufRead> BufRead for Take<T> {
|
||
|
fn fill_buf(&mut self) -> Result<&[u8]> {
|
||
|
// Don't call into inner reader at all at EOF because it may still block
|
||
|
@@ -2079,13 +2060,11 @@ impl<T: BufRead> BufRead for Take<T> {
|
||
|
/// Please see the documentation of [`bytes`] for more details.
|
||
|
///
|
||
|
/// [`bytes`]: trait.Read.html#method.bytes
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
#[derive(Debug)]
|
||
|
pub struct Bytes<R> {
|
||
|
inner: R,
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl<R: Read> Iterator for Bytes<R> {
|
||
|
type Item = Result<u8>;
|
||
|
|
||
|
@@ -2109,14 +2088,14 @@ impl<R: Read> Iterator for Bytes<R> {
|
||
|
/// `BufRead`. Please see the documentation of `split()` for more details.
|
||
|
///
|
||
|
/// [split]: trait.BufRead.html#method.split
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
#[derive(Debug)]
|
||
|
pub struct Split<B> {
|
||
|
buf: B,
|
||
|
delim: u8,
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl<B: BufRead> Iterator for Split<B> {
|
||
|
type Item = Result<Vec<u8>>;
|
||
|
|
||
|
@@ -2141,13 +2120,13 @@ impl<B: BufRead> Iterator for Split<B> {
|
||
|
/// `BufRead`. Please see the documentation of `lines()` for more details.
|
||
|
///
|
||
|
/// [lines]: trait.BufRead.html#method.lines
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
#[derive(Debug)]
|
||
|
pub struct Lines<B> {
|
||
|
buf: B,
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl<B: BufRead> Iterator for Lines<B> {
|
||
|
type Item = Result<String>;
|
||
|
|
||
|
diff --git a/prelude.rs b/prelude.rs
|
||
|
index 2e19edf..66294a3 100644
|
||
|
--- a/prelude.rs
|
||
|
+++ b/prelude.rs
|
||
|
@@ -8,7 +8,8 @@
|
||
|
//! use std::io::prelude::*;
|
||
|
//! ```
|
||
|
|
||
|
-#![stable(feature = "rust1", since = "1.0.0")]
|
||
|
+pub use super::{Read, Write, Seek};
|
||
|
+#[cfg(feature="collections")] pub use super::BufRead;
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
-pub use super::{Read, Write, BufRead, Seek};
|
||
|
+#[cfg(feature="collections")] pub use alloc::boxed::Box;
|
||
|
+#[cfg(feature="collections")] pub use collections::vec::Vec;
|
||
|
diff --git a/util.rs b/util.rs
|
||
|
index 6aaf8f1..447ce47 100644
|
||
|
--- a/util.rs
|
||
|
+++ b/util.rs
|
||
|
@@ -1,8 +1,9 @@
|
||
|
#![allow(missing_copy_implementations)]
|
||
|
|
||
|
-use crate::fmt;
|
||
|
-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut};
|
||
|
-use crate::mem;
|
||
|
+use core::fmt;
|
||
|
+use crate::io::{self, Read, Initializer, Write, ErrorKind};
|
||
|
+#[cfg(feature="collections")] use crate::io::{BufRead, IoVec, IoVecMut};
|
||
|
+use core::mem;
|
||
|
|
||
|
/// Copies the entire contents of a reader into a writer.
|
||
|
///
|
||
|
@@ -39,7 +40,6 @@ use crate::mem;
|
||
|
/// Ok(())
|
||
|
/// }
|
||
|
/// ```
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<u64>
|
||
|
where R: Read, W: Write
|
||
|
{
|
||
|
@@ -68,7 +68,6 @@ pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<
|
||
|
/// the documentation of [`empty()`][`empty`] for more details.
|
||
|
///
|
||
|
/// [`empty`]: fn.empty.html
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub struct Empty { _priv: () }
|
||
|
|
||
|
/// Constructs a new handle to an empty reader.
|
||
|
@@ -88,10 +87,8 @@ pub struct Empty { _priv: () }
|
||
|
/// io::empty().read_to_string(&mut buffer).unwrap();
|
||
|
/// assert!(buffer.is_empty());
|
||
|
/// ```
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn empty() -> Empty { Empty { _priv: () } }
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl Read for Empty {
|
||
|
#[inline]
|
||
|
fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> { Ok(0) }
|
||
|
@@ -101,7 +98,8 @@ impl Read for Empty {
|
||
|
Initializer::nop()
|
||
|
}
|
||
|
}
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
+
|
||
|
+#[cfg(feature="collections")]
|
||
|
impl BufRead for Empty {
|
||
|
#[inline]
|
||
|
fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) }
|
||
|
@@ -109,7 +107,6 @@ impl BufRead for Empty {
|
||
|
fn consume(&mut self, _n: usize) {}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "std_debug", since = "1.16.0")]
|
||
|
impl fmt::Debug for Empty {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||
|
f.pad("Empty { .. }")
|
||
|
@@ -122,7 +119,6 @@ impl fmt::Debug for Empty {
|
||
|
/// see the documentation of `repeat()` for more details.
|
||
|
///
|
||
|
/// [repeat]: fn.repeat.html
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub struct Repeat { byte: u8 }
|
||
|
|
||
|
/// Creates an instance of a reader that infinitely repeats one byte.
|
||
|
@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 }
|
||
|
/// io::repeat(0b101).read_exact(&mut buffer).unwrap();
|
||
|
/// assert_eq!(buffer, [0b101, 0b101, 0b101]);
|
||
|
/// ```
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn repeat(byte: u8) -> Repeat { Repeat { byte } }
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl Read for Repeat {
|
||
|
#[inline]
|
||
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||
|
@@ -152,6 +146,7 @@ impl Read for Repeat {
|
||
|
Ok(buf.len())
|
||
|
}
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result<usize> {
|
||
|
let mut nwritten = 0;
|
||
|
@@ -167,7 +162,6 @@ impl Read for Repeat {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "std_debug", since = "1.16.0")]
|
||
|
impl fmt::Debug for Repeat {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||
|
f.pad("Repeat { .. }")
|
||
|
@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat {
|
||
|
/// see the documentation of `sink()` for more details.
|
||
|
///
|
||
|
/// [sink]: fn.sink.html
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub struct Sink { _priv: () }
|
||
|
|
||
|
/// Creates an instance of a writer which will successfully consume all data.
|
||
|
@@ -197,14 +190,13 @@ pub struct Sink { _priv: () }
|
||
|
/// let num_bytes = io::sink().write(&buffer).unwrap();
|
||
|
/// assert_eq!(num_bytes, 5);
|
||
|
/// ```
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
pub fn sink() -> Sink { Sink { _priv: () } }
|
||
|
|
||
|
-#[stable(feature = "rust1", since = "1.0.0")]
|
||
|
impl Write for Sink {
|
||
|
#[inline]
|
||
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { Ok(buf.len()) }
|
||
|
|
||
|
+ #[cfg(feature="collections")]
|
||
|
#[inline]
|
||
|
fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result<usize> {
|
||
|
let total_len = bufs.iter().map(|b| b.len()).sum();
|
||
|
@@ -215,7 +207,6 @@ impl Write for Sink {
|
||
|
fn flush(&mut self) -> io::Result<()> { Ok(()) }
|
||
|
}
|
||
|
|
||
|
-#[stable(feature = "std_debug", since = "1.16.0")]
|
||
|
impl fmt::Debug for Sink {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||
|
f.pad("Sink { .. }")
|