12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634 |
- diff --git a/buffered.rs b/buffered.rs
- index 6d3fbc9..548f596 100644
- --- a/buffered.rs
- +++ b/buffered.rs
- @@ -10,13 +10,13 @@
-
- //! Buffering wrappers for I/O traits
-
- +use core::prelude::v1::*;
- use io::prelude::*;
-
- -use cmp;
- -use error;
- -use fmt;
- +use core::cmp;
- +use core::fmt;
- use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom};
- -use memchr;
- +use io::memchr;
-
- /// The `BufReader` struct adds buffering to any reader.
- ///
- @@ -46,7 +46,6 @@ use memchr;
- /// # Ok(())
- /// # }
- /// ```
- -#[stable(feature = "rust1", since = "1.0.0")]
- pub struct BufReader<R> {
- inner: R,
- buf: Box<[u8]>,
- @@ -69,7 +68,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)
- }
- @@ -90,7 +88,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);
- @@ -123,7 +120,6 @@ impl<R: Read> 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.
- @@ -144,7 +140,6 @@ impl<R: Read> BufReader<R> {
- /// # Ok(())
- /// # }
- /// ```
- - #[stable(feature = "rust1", since = "1.0.0")]
- pub fn get_mut(&mut self) -> &mut R { &mut self.inner }
-
- /// Returns `true` if there are no bytes in the internal buffer.
- @@ -167,7 +162,6 @@ impl<R: Read> BufReader<R> {
- /// # Ok(())
- /// # }
- /// ```
- - #[unstable(feature = "bufreader_is_empty", issue = "45323", reason = "recently added")]
- pub fn is_empty(&self) -> bool {
- self.pos == self.cap
- }
- @@ -190,11 +184,9 @@ impl<R: Read> BufReader<R> {
- /// # Ok(())
- /// # }
- /// ```
- - #[stable(feature = "rust1", since = "1.0.0")]
- pub fn into_inner(self) -> R { self.inner }
- }
-
- -#[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
- @@ -217,7 +209,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
- @@ -237,7 +228,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")
- @@ -247,7 +237,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.
- ///
- @@ -345,7 +334,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>,
- @@ -380,7 +368,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> {
- @@ -394,7 +381,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)
- }
- @@ -412,7 +398,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),
- @@ -461,7 +446,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.
- @@ -479,7 +463,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() }
-
- /// Unwraps this `BufWriter`, returning the underlying writer.
- @@ -497,7 +480,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)),
- @@ -506,7 +488,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() {
- @@ -526,7 +507,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")
- @@ -536,7 +516,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.
- ///
- @@ -546,7 +525,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 {
- @@ -585,7 +563,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.
- @@ -618,23 +595,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)
- @@ -689,7 +656,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,
- @@ -710,7 +676,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)
- @@ -731,7 +696,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),
- @@ -755,7 +719,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.
- @@ -778,7 +741,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.
- @@ -800,7 +762,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 {
- @@ -811,7 +772,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 {
- @@ -856,7 +816,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 32a9214..21ed409 100644
- --- a/cursor.rs
- +++ b/cursor.rs
- @@ -8,10 +8,11 @@
- // option. This file may not be copied, modified, or distributed
- // except according to those terms.
-
- +use core::prelude::v1::*;
- use io::prelude::*;
-
- -use core::convert::TryInto;
- -use cmp;
- +#[cfg(feature = "collections")] use core::convert::TryInto;
- +use core::cmp;
- use io::{self, Initializer, SeekFrom, Error, ErrorKind};
-
- /// A `Cursor` wraps another type and provides it with a
- @@ -79,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind};
- /// 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,
- @@ -102,7 +102,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 }
- }
- @@ -120,7 +119,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.
- @@ -136,7 +134,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.
- @@ -155,7 +152,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.
- @@ -177,7 +173,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.
- @@ -197,11 +192,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 {
- @@ -222,10 +215,9 @@ 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)
- }
- @@ -236,16 +228,19 @@ 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; }
- }
-
- -#[stable(feature = "rust1", since = "1.0.0")]
- impl<'a> Write for Cursor<&'a mut [u8]> {
- #[inline]
- fn write(&mut self, data: &[u8]) -> io::Result<usize> {
- @@ -257,7 +252,7 @@ impl<'a> Write for Cursor<&'a mut [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> {
- let pos: usize = self.position().try_into().map_err(|_| {
- @@ -287,8 +282,8 @@ 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> {
- let pos = cmp::min(self.pos, self.inner.len() as u64);
- diff --git a/error.rs b/error.rs
- index bb9383d..01ddea6 100644
- --- a/error.rs
- +++ b/error.rs
- @@ -8,11 +8,16 @@
- // option. This file may not be copied, modified, or distributed
- // except according to those terms.
-
- -use error;
- -use fmt;
- -use result;
- -use sys;
- -use 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.
- @@ -48,7 +53,6 @@ use 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
- @@ -63,7 +67,6 @@ pub type Result<T> = result::Result<T, Error>;
- /// [`Seek`]: ../io/trait.Seek.html
- /// [`ErrorKind`]: enum.ErrorKind.html
- #[derive(Debug)]
- -#[stable(feature = "rust1", since = "1.0.0")]
- pub struct Error {
- repr: Repr,
- }
- @@ -71,13 +74,16 @@ pub struct 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<error::Error+Send+Sync>,
- + error: String,
- }
-
- /// A list specifying general categories of I/O error.
- @@ -89,47 +95,34 @@ 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)]
- 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.
- ///
- @@ -141,10 +134,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)`].
- @@ -155,15 +146,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
- @@ -172,15 +160,10 @@ 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,
-
- /// A marker variant that tells the compiler that users of this enum cannot
- /// match it exhaustively.
- - #[unstable(feature = "io_error_internals",
- - reason = "better expressed through extensible enums that this \
- - enum cannot be exhaustively matched against",
- - issue = "0")]
- #[doc(hidden)]
- __Nonexhaustive,
- }
- @@ -213,7 +196,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 {
- #[inline]
- fn from(kind: ErrorKind) -> Error {
- @@ -242,14 +224,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<error::Error+Send+Sync>>
- + where E: Into<String>
- {
- Self::_new(kind, error.into())
- }
-
- - fn _new(kind: ErrorKind, error: Box<error::Error+Send+Sync>) -> Error {
- + fn _new(kind: ErrorKind, error: String) -> Error {
- Error {
- repr: Repr::Custom(Box::new(Custom {
- kind,
- @@ -258,24 +239,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
- @@ -301,7 +264,6 @@ impl Error {
- /// assert_eq!(error.kind(), io::ErrorKind::AddrInUse);
- /// # }
- /// ```
- - #[stable(feature = "rust1", since = "1.0.0")]
- pub fn from_raw_os_error(code: i32) -> Error {
- Error { repr: Repr::Os(code) }
- }
- @@ -332,7 +294,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),
- @@ -366,12 +327,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<&(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),
- }
- }
-
- @@ -437,12 +397,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 (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),
- }
- }
-
- @@ -471,8 +430,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<error::Error+Send+Sync>> {
- + pub fn into_inner(self) -> Option<String> {
- match self.repr {
- Repr::Os(..) => None,
- Repr::Simple(..) => None,
- @@ -498,10 +456,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,
- }
- @@ -512,21 +469,18 @@ impl fmt::Debug for Repr {
- fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
- match *self {
- Repr::Os(ref code) =>
- - fmt.debug_struct("Os").field("code", code)
- - .field("message", &sys::os::error_string(*code)).finish(),
- + fmt.debug_struct("Os").field("code", code).finish(),
- Repr::Custom(ref c) => fmt.debug_tuple("Custom").field(c).finish(),
- 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()),
- @@ -534,24 +488,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(),
- - }
- - }
- -
- - fn cause(&self) -> Option<&error::Error> {
- - match self.repr {
- - Repr::Os(..) => None,
- - Repr::Simple(..) => None,
- - Repr::Custom(ref c) => c.error.cause(),
- - }
- - }
- -}
- -
- 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 fe1179a..452b8b7 100644
- --- a/impls.rs
- +++ b/impls.rs
- @@ -8,15 +8,18 @@
- // option. This file may not be copied, modified, or distributed
- // except according to those terms.
-
- -use cmp;
- -use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind};
- -use fmt;
- -use mem;
- +#[cfg(feature="alloc")] use alloc::boxed::Box;
- +use core::cmp;
- +use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind};
- +#[cfg(feature="collections")] use io::BufRead;
- +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<'a, R: Read + ?Sized> Read for &'a mut R {
- #[inline]
- fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
- @@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a 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)
- @@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R {
- (**self).read_exact(buf)
- }
- }
- -#[stable(feature = "rust1", since = "1.0.0")]
- impl<'a, W: Write + ?Sized> Write for &'a mut W {
- #[inline]
- fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (**self).write(buf) }
- @@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W {
- (**self).write_fmt(fmt)
- }
- }
- -#[stable(feature = "rust1", since = "1.0.0")]
- impl<'a, S: Seek + ?Sized> Seek for &'a 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<'a, B: BufRead + ?Sized> BufRead for &'a mut B {
- #[inline]
- fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() }
- @@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a 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> {
- @@ -97,11 +100,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)
- @@ -112,7 +117,7 @@ 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) }
- @@ -130,12 +135,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() }
- @@ -161,7 +166,6 @@ impl<B: BufRead + ?Sized> BufRead for Box<B> {
- ///
- /// 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<'a> Read for &'a [u8] {
- #[inline]
- fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
- @@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] {
- Ok(())
- }
-
- + #[cfg(feature="collections")]
- #[inline]
- fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
- buf.extend_from_slice(*self);
- @@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] {
- }
- }
-
- -#[stable(feature = "rust1", since = "1.0.0")]
- +#[cfg(feature="collections")]
- impl<'a> BufRead for &'a [u8] {
- #[inline]
- fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) }
- @@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [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<'a> Write for &'a mut [u8] {
- #[inline]
- fn write(&mut self, data: &[u8]) -> io::Result<usize> {
- @@ -256,7 +260,7 @@ impl<'a> Write for &'a 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> {
- diff --git a/memchr.rs b/memchr.rs
- index 50f998e..a8bff09 100644
- --- a/memchr.rs
- +++ b/memchr.rs
- @@ -11,10 +11,12 @@
- // Original implementation taken from rust-memchr
- // Copyright 2015 Andrew Gallant, bluss and Nicolas Koch
-
- +pub use self::fallback::{memchr,memrchr};
- +
- #[allow(dead_code)]
- pub mod fallback {
- - use cmp;
- - use mem;
- + use core::cmp;
- + use core::mem;
-
- const LO_U64: u64 = 0x0101010101010101;
- const HI_U64: u64 = 0x8080808080808080;
- diff --git a/mod.rs b/mod.rs
- index 57f8c39..f9cb93d 100644
- --- a/mod.rs
- +++ b/mod.rs
- @@ -268,50 +268,35 @@
- //! [`Result`]: ../result/enum.Result.html
- //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap
-
- -#![stable(feature = "rust1", since = "1.0.0")]
- -
- -use cmp;
- +use core::cmp;
- use core::str as core_str;
- -use error as std_error;
- -use fmt;
- -use result;
- -use str;
- -use memchr;
- -use ptr;
- -
- -#[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::fmt;
- +use core::result;
- +#[cfg(feature="collections")] use collections::string::String;
- +use core::str;
- +#[cfg(feature="collections")] use collections::vec::Vec;
- +mod memchr;
- +use core::ptr;
- +
- +#[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 = ::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<'a> Drop for Guard<'a> {
- fn drop(&mut self) {
- unsafe { self.buf.set_len(self.len); }
- @@ -336,6 +321,7 @@ impl<'a> Drop for Guard<'a> {
- // 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>
- {
- @@ -363,6 +349,7 @@ 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> {
- let start_len = buf.len();
- let mut g = Guard { len: buf.len(), buf: buf };
- @@ -449,7 +436,6 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
- /// # Ok(())
- /// # }
- /// ```
- -#[stable(feature = "rust1", since = "1.0.0")]
- pub trait Read {
- /// Pull some bytes from this source into the specified buffer, returning
- /// how many bytes were read.
- @@ -505,7 +491,6 @@ pub trait Read {
- /// # Ok(())
- /// # }
- /// ```
- - #[stable(feature = "rust1", since = "1.0.0")]
- fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
-
- /// Determines if this `Read`er can work with buffers of uninitialized
- @@ -530,7 +515,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()
- @@ -578,7 +562,7 @@ pub trait Read {
- /// # Ok(())
- /// # }
- /// ```
- - #[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)
- }
- @@ -616,7 +600,7 @@ pub trait Read {
- /// # Ok(())
- /// # }
- /// ```
- - #[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`
- @@ -679,7 +663,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) {
- @@ -731,7 +714,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.
- @@ -768,7 +750,6 @@ pub trait Read {
- /// # Ok(())
- /// # }
- /// ```
- - #[stable(feature = "rust1", since = "1.0.0")]
- fn bytes(self) -> Bytes<Self> where Self: Sized {
- Bytes { inner: self }
- }
- @@ -809,10 +790,6 @@ pub trait Read {
- /// # Ok(())
- /// # }
- /// ```
- - #[unstable(feature = "io", reason = "the semantics of a partial read/write \
- - of where errors happen is currently \
- - unclear and may change",
- - issue = "27802")]
- fn chars(self) -> Chars<Self> where Self: Sized {
- Chars { inner: self }
- }
- @@ -847,7 +824,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 }
- }
- @@ -883,20 +859,17 @@ 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 }
- }
- }
-
- /// 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)
- @@ -910,21 +883,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() {
- @@ -967,7 +937,6 @@ impl Initializer {
- /// # Ok(())
- /// # }
- /// ```
- -#[stable(feature = "rust1", since = "1.0.0")]
- pub trait Write {
- /// Write a buffer into this object, returning how many bytes were written.
- ///
- @@ -1011,7 +980,6 @@ pub trait Write {
- /// # Ok(())
- /// # }
- /// ```
- - #[stable(feature = "rust1", since = "1.0.0")]
- fn write(&mut self, buf: &[u8]) -> Result<usize>;
-
- /// Flush this output stream, ensuring that all intermediately buffered
- @@ -1037,7 +1005,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 write.
- @@ -1067,7 +1034,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) {
- @@ -1119,7 +1085,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
- @@ -1175,7 +1140,6 @@ pub trait Write {
- /// # Ok(())
- /// # }
- /// ```
- - #[stable(feature = "rust1", since = "1.0.0")]
- fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
- }
-
- @@ -1205,7 +1169,6 @@ pub trait Write {
- /// # Ok(())
- /// # }
- /// ```
- -#[stable(feature = "rust1", since = "1.0.0")]
- pub trait Seek {
- /// Seek to an offset, in bytes, in a stream.
- ///
- @@ -1221,7 +1184,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>;
- }
-
- @@ -1231,29 +1193,26 @@ pub trait Seek {
- ///
- /// [`Seek`]: trait.Seek.html
- #[derive(Copy, PartialEq, Eq, Clone, Debug)]
- -#[stable(feature = "rust1", since = "1.0.0")]
- pub enum SeekFrom {
- /// Set 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),
-
- /// Set 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),
-
- /// Set 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;
- @@ -1333,7 +1292,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 {
- /// Fills the internal buffer of this object, returning the buffer contents.
- ///
- @@ -1378,7 +1337,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,
- @@ -1400,7 +1358,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.
- @@ -1458,7 +1415,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)
- }
- @@ -1515,7 +1471,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
- @@ -1556,7 +1511,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 }
- }
- @@ -1595,7 +1549,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 }
- }
- @@ -1607,7 +1560,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,
- @@ -1633,7 +1585,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)
- }
- @@ -1656,7 +1607,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)
- }
- @@ -1683,13 +1633,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")
- @@ -1699,7 +1647,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 {
- @@ -1721,7 +1668,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 {
- @@ -1748,7 +1695,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,
- @@ -1783,7 +1729,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
- @@ -1810,7 +1755,6 @@ impl<T> Take<T> {
- /// # Ok(())
- /// # }
- /// ```
- - #[unstable(feature = "take_set_limit", issue = "42781")]
- pub fn set_limit(&mut self, limit: u64) {
- self.limit = limit;
- }
- @@ -1835,7 +1779,6 @@ impl<T> Take<T> {
- /// # Ok(())
- /// # }
- /// ```
- - #[stable(feature = "io_take_into_inner", since = "1.15.0")]
- pub fn into_inner(self) -> T {
- self.inner
- }
- @@ -1860,7 +1803,6 @@ impl<T> Take<T> {
- /// # Ok(())
- /// # }
- /// ```
- - #[stable(feature = "more_io_inner_methods", since = "1.20.0")]
- pub fn get_ref(&self) -> &T {
- &self.inner
- }
- @@ -1889,13 +1831,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
- @@ -1914,7 +1854,7 @@ impl<T: Read> Read for Take<T> {
- }
- }
-
- -#[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
- @@ -1953,13 +1893,11 @@ fn read_one_byte(reader: &mut Read) -> Option<Result<u8>> {
- /// 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>;
-
- @@ -1974,8 +1912,6 @@ impl<R: Read> Iterator for Bytes<R> {
- /// Please see the documentation of `chars()` for more details.
- ///
- /// [chars]: trait.Read.html#method.chars
- -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
- - issue = "27802")]
- #[derive(Debug)]
- pub struct Chars<R> {
- inner: R,
- @@ -1984,8 +1920,6 @@ pub struct Chars<R> {
- /// An enumeration of possible errors that can be generated from the `Chars`
- /// adapter.
- #[derive(Debug)]
- -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
- - issue = "27802")]
- pub enum CharsError {
- /// Variant representing that the underlying stream was read successfully
- /// but it did not contain valid utf8 data.
- @@ -1995,8 +1929,6 @@ pub enum CharsError {
- Other(Error),
- }
-
- -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
- - issue = "27802")]
- impl<R: Read> Iterator for Chars<R> {
- type Item = result::Result<char, CharsError>;
-
- @@ -2028,25 +1960,6 @@ impl<R: Read> Iterator for Chars<R> {
- }
- }
-
- -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
- - issue = "27802")]
- -impl std_error::Error for CharsError {
- - fn description(&self) -> &str {
- - match *self {
- - CharsError::NotUtf8 => "invalid utf8 encoding",
- - CharsError::Other(ref e) => std_error::Error::description(e),
- - }
- - }
- - fn cause(&self) -> Option<&std_error::Error> {
- - match *self {
- - CharsError::NotUtf8 => None,
- - CharsError::Other(ref e) => e.cause(),
- - }
- - }
- -}
- -
- -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
- - issue = "27802")]
- impl fmt::Display for CharsError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- match *self {
- @@ -2065,14 +1978,14 @@ impl fmt::Display for CharsError {
- /// `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>>;
-
- @@ -2097,13 +2010,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 8772d0f..49d66c9 100644
- --- a/prelude.rs
- +++ b/prelude.rs
- @@ -18,7 +18,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 45d281e..0efc3b1 100644
- --- a/util.rs
- +++ b/util.rs
- @@ -10,9 +10,10 @@
-
- #![allow(missing_copy_implementations)]
-
- -use fmt;
- -use io::{self, Read, Initializer, Write, ErrorKind, BufRead};
- -use mem;
- +use core::fmt;
- +use io::{self, Read, Initializer, Write, ErrorKind};
- +use core::mem;
- +#[cfg(feature="collections")] use io::BufRead;
-
- /// Copies the entire contents of a reader into a writer.
- ///
- @@ -45,7 +46,6 @@ use mem;
- /// # }
- /// # foo().unwrap();
- /// ```
- -#[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
- {
- @@ -74,7 +74,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.
- @@ -94,10 +93,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) }
- @@ -107,7 +104,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(&[]) }
- @@ -115,7 +113,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 { .. }")
- @@ -128,7 +125,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.
- @@ -145,10 +141,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: byte } }
-
- -#[stable(feature = "rust1", since = "1.0.0")]
- impl Read for Repeat {
- #[inline]
- fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
- @@ -164,7 +158,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 { .. }")
- @@ -177,7 +170,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.
- @@ -194,10 +186,8 @@ 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()) }
- @@ -205,7 +195,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 { .. }")
|