d280b40b18532dfeb80b1a98109fa6218630b939.patch 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610
  1. diff --git a/buffered.rs b/buffered.rs
  2. index 296ee78..4262dc5 100644
  3. --- a/buffered.rs
  4. +++ b/buffered.rs
  5. @@ -10,13 +10,13 @@
  6. //! Buffering wrappers for I/O traits
  7. +use core::prelude::v1::*;
  8. use io::prelude::*;
  9. -use cmp;
  10. -use error;
  11. -use fmt;
  12. +use core::cmp;
  13. +use core::fmt;
  14. use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom};
  15. -use memchr;
  16. +use io::memchr;
  17. /// The `BufReader` struct adds buffering to any reader.
  18. ///
  19. @@ -46,7 +46,6 @@ use memchr;
  20. /// # Ok(())
  21. /// # }
  22. /// ```
  23. -#[stable(feature = "rust1", since = "1.0.0")]
  24. pub struct BufReader<R> {
  25. inner: R,
  26. buf: Box<[u8]>,
  27. @@ -69,7 +68,6 @@ impl<R: Read> BufReader<R> {
  28. /// # Ok(())
  29. /// # }
  30. /// ```
  31. - #[stable(feature = "rust1", since = "1.0.0")]
  32. pub fn new(inner: R) -> BufReader<R> {
  33. BufReader::with_capacity(DEFAULT_BUF_SIZE, inner)
  34. }
  35. @@ -90,7 +88,6 @@ impl<R: Read> BufReader<R> {
  36. /// # Ok(())
  37. /// # }
  38. /// ```
  39. - #[stable(feature = "rust1", since = "1.0.0")]
  40. pub fn with_capacity(cap: usize, inner: R) -> BufReader<R> {
  41. unsafe {
  42. let mut buffer = Vec::with_capacity(cap);
  43. @@ -123,7 +120,6 @@ impl<R: Read> BufReader<R> {
  44. /// # Ok(())
  45. /// # }
  46. /// ```
  47. - #[stable(feature = "rust1", since = "1.0.0")]
  48. pub fn get_ref(&self) -> &R { &self.inner }
  49. /// Gets a mutable reference to the underlying reader.
  50. @@ -144,7 +140,6 @@ impl<R: Read> BufReader<R> {
  51. /// # Ok(())
  52. /// # }
  53. /// ```
  54. - #[stable(feature = "rust1", since = "1.0.0")]
  55. pub fn get_mut(&mut self) -> &mut R { &mut self.inner }
  56. /// Unwraps this `BufReader`, returning the underlying reader.
  57. @@ -165,11 +160,9 @@ impl<R: Read> BufReader<R> {
  58. /// # Ok(())
  59. /// # }
  60. /// ```
  61. - #[stable(feature = "rust1", since = "1.0.0")]
  62. pub fn into_inner(self) -> R { self.inner }
  63. }
  64. -#[stable(feature = "rust1", since = "1.0.0")]
  65. impl<R: Read> Read for BufReader<R> {
  66. fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
  67. // If we don't have any buffered data and we're doing a massive read
  68. @@ -192,7 +185,6 @@ impl<R: Read> Read for BufReader<R> {
  69. }
  70. }
  71. -#[stable(feature = "rust1", since = "1.0.0")]
  72. impl<R: Read> BufRead for BufReader<R> {
  73. fn fill_buf(&mut self) -> io::Result<&[u8]> {
  74. // If we've reached the end of our internal buffer then we need to fetch
  75. @@ -212,7 +204,6 @@ impl<R: Read> BufRead for BufReader<R> {
  76. }
  77. }
  78. -#[stable(feature = "rust1", since = "1.0.0")]
  79. impl<R> fmt::Debug for BufReader<R> where R: fmt::Debug {
  80. fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
  81. fmt.debug_struct("BufReader")
  82. @@ -222,7 +213,6 @@ impl<R> fmt::Debug for BufReader<R> where R: fmt::Debug {
  83. }
  84. }
  85. -#[stable(feature = "rust1", since = "1.0.0")]
  86. impl<R: Seek> Seek for BufReader<R> {
  87. /// Seek to an offset, in bytes, in the underlying reader.
  88. ///
  89. @@ -316,7 +306,6 @@ impl<R: Seek> Seek for BufReader<R> {
  90. /// [`Write`]: ../../std/io/trait.Write.html
  91. /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write
  92. /// [`TcpStream`]: ../../std/net/struct.TcpStream.html
  93. -#[stable(feature = "rust1", since = "1.0.0")]
  94. pub struct BufWriter<W: Write> {
  95. inner: Option<W>,
  96. buf: Vec<u8>,
  97. @@ -351,7 +340,6 @@ pub struct BufWriter<W: Write> {
  98. /// };
  99. /// ```
  100. #[derive(Debug)]
  101. -#[stable(feature = "rust1", since = "1.0.0")]
  102. pub struct IntoInnerError<W>(W, Error);
  103. impl<W: Write> BufWriter<W> {
  104. @@ -365,7 +353,6 @@ impl<W: Write> BufWriter<W> {
  105. ///
  106. /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
  107. /// ```
  108. - #[stable(feature = "rust1", since = "1.0.0")]
  109. pub fn new(inner: W) -> BufWriter<W> {
  110. BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner)
  111. }
  112. @@ -383,7 +370,6 @@ impl<W: Write> BufWriter<W> {
  113. /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap();
  114. /// let mut buffer = BufWriter::with_capacity(100, stream);
  115. /// ```
  116. - #[stable(feature = "rust1", since = "1.0.0")]
  117. pub fn with_capacity(cap: usize, inner: W) -> BufWriter<W> {
  118. BufWriter {
  119. inner: Some(inner),
  120. @@ -432,7 +418,6 @@ impl<W: Write> BufWriter<W> {
  121. /// // we can use reference just like buffer
  122. /// let reference = buffer.get_ref();
  123. /// ```
  124. - #[stable(feature = "rust1", since = "1.0.0")]
  125. pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() }
  126. /// Gets a mutable reference to the underlying writer.
  127. @@ -450,7 +435,6 @@ impl<W: Write> BufWriter<W> {
  128. /// // we can use reference just like buffer
  129. /// let reference = buffer.get_mut();
  130. /// ```
  131. - #[stable(feature = "rust1", since = "1.0.0")]
  132. pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() }
  133. /// Unwraps this `BufWriter`, returning the underlying writer.
  134. @@ -468,7 +452,6 @@ impl<W: Write> BufWriter<W> {
  135. /// // unwrap the TcpStream and flush the buffer
  136. /// let stream = buffer.into_inner().unwrap();
  137. /// ```
  138. - #[stable(feature = "rust1", since = "1.0.0")]
  139. pub fn into_inner(mut self) -> Result<W, IntoInnerError<BufWriter<W>>> {
  140. match self.flush_buf() {
  141. Err(e) => Err(IntoInnerError(self, e)),
  142. @@ -477,7 +460,6 @@ impl<W: Write> BufWriter<W> {
  143. }
  144. }
  145. -#[stable(feature = "rust1", since = "1.0.0")]
  146. impl<W: Write> Write for BufWriter<W> {
  147. fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
  148. if self.buf.len() + buf.len() > self.buf.capacity() {
  149. @@ -497,7 +479,6 @@ impl<W: Write> Write for BufWriter<W> {
  150. }
  151. }
  152. -#[stable(feature = "rust1", since = "1.0.0")]
  153. impl<W: Write> fmt::Debug for BufWriter<W> where W: fmt::Debug {
  154. fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
  155. fmt.debug_struct("BufWriter")
  156. @@ -507,7 +488,6 @@ impl<W: Write> fmt::Debug for BufWriter<W> where W: fmt::Debug {
  157. }
  158. }
  159. -#[stable(feature = "rust1", since = "1.0.0")]
  160. impl<W: Write + Seek> Seek for BufWriter<W> {
  161. /// Seek to the offset, in bytes, in the underlying writer.
  162. ///
  163. @@ -517,7 +497,6 @@ impl<W: Write + Seek> Seek for BufWriter<W> {
  164. }
  165. }
  166. -#[stable(feature = "rust1", since = "1.0.0")]
  167. impl<W: Write> Drop for BufWriter<W> {
  168. fn drop(&mut self) {
  169. if self.inner.is_some() && !self.panicked {
  170. @@ -556,7 +535,6 @@ impl<W> IntoInnerError<W> {
  171. /// }
  172. /// };
  173. /// ```
  174. - #[stable(feature = "rust1", since = "1.0.0")]
  175. pub fn error(&self) -> &Error { &self.1 }
  176. /// Returns the buffered writer instance which generated the error.
  177. @@ -589,23 +567,13 @@ impl<W> IntoInnerError<W> {
  178. /// }
  179. /// };
  180. /// ```
  181. - #[stable(feature = "rust1", since = "1.0.0")]
  182. pub fn into_inner(self) -> W { self.0 }
  183. }
  184. -#[stable(feature = "rust1", since = "1.0.0")]
  185. impl<W> From<IntoInnerError<W>> for Error {
  186. fn from(iie: IntoInnerError<W>) -> Error { iie.1 }
  187. }
  188. -#[stable(feature = "rust1", since = "1.0.0")]
  189. -impl<W: Send + fmt::Debug> error::Error for IntoInnerError<W> {
  190. - fn description(&self) -> &str {
  191. - error::Error::description(self.error())
  192. - }
  193. -}
  194. -
  195. -#[stable(feature = "rust1", since = "1.0.0")]
  196. impl<W> fmt::Display for IntoInnerError<W> {
  197. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  198. self.error().fmt(f)
  199. @@ -660,7 +628,6 @@ impl<W> fmt::Display for IntoInnerError<W> {
  200. /// # Ok(())
  201. /// # }
  202. /// ```
  203. -#[stable(feature = "rust1", since = "1.0.0")]
  204. pub struct LineWriter<W: Write> {
  205. inner: BufWriter<W>,
  206. need_flush: bool,
  207. @@ -681,7 +648,6 @@ impl<W: Write> LineWriter<W> {
  208. /// # Ok(())
  209. /// # }
  210. /// ```
  211. - #[stable(feature = "rust1", since = "1.0.0")]
  212. pub fn new(inner: W) -> LineWriter<W> {
  213. // Lines typically aren't that long, don't use a giant buffer
  214. LineWriter::with_capacity(1024, inner)
  215. @@ -702,7 +668,6 @@ impl<W: Write> LineWriter<W> {
  216. /// # Ok(())
  217. /// # }
  218. /// ```
  219. - #[stable(feature = "rust1", since = "1.0.0")]
  220. pub fn with_capacity(cap: usize, inner: W) -> LineWriter<W> {
  221. LineWriter {
  222. inner: BufWriter::with_capacity(cap, inner),
  223. @@ -726,7 +691,6 @@ impl<W: Write> LineWriter<W> {
  224. /// # Ok(())
  225. /// # }
  226. /// ```
  227. - #[stable(feature = "rust1", since = "1.0.0")]
  228. pub fn get_ref(&self) -> &W { self.inner.get_ref() }
  229. /// Gets a mutable reference to the underlying writer.
  230. @@ -749,7 +713,6 @@ impl<W: Write> LineWriter<W> {
  231. /// # Ok(())
  232. /// # }
  233. /// ```
  234. - #[stable(feature = "rust1", since = "1.0.0")]
  235. pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() }
  236. /// Unwraps this `LineWriter`, returning the underlying writer.
  237. @@ -771,7 +734,6 @@ impl<W: Write> LineWriter<W> {
  238. /// # Ok(())
  239. /// # }
  240. /// ```
  241. - #[stable(feature = "rust1", since = "1.0.0")]
  242. pub fn into_inner(self) -> Result<W, IntoInnerError<LineWriter<W>>> {
  243. self.inner.into_inner().map_err(|IntoInnerError(buf, e)| {
  244. IntoInnerError(LineWriter {
  245. @@ -782,7 +744,6 @@ impl<W: Write> LineWriter<W> {
  246. }
  247. }
  248. -#[stable(feature = "rust1", since = "1.0.0")]
  249. impl<W: Write> Write for LineWriter<W> {
  250. fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
  251. if self.need_flush {
  252. @@ -827,7 +788,6 @@ impl<W: Write> Write for LineWriter<W> {
  253. }
  254. }
  255. -#[stable(feature = "rust1", since = "1.0.0")]
  256. impl<W: Write> fmt::Debug for LineWriter<W> where W: fmt::Debug {
  257. fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
  258. fmt.debug_struct("LineWriter")
  259. diff --git a/cursor.rs b/cursor.rs
  260. index 616b4f4..97d1076 100644
  261. --- a/cursor.rs
  262. +++ b/cursor.rs
  263. @@ -8,10 +8,11 @@
  264. // option. This file may not be copied, modified, or distributed
  265. // except according to those terms.
  266. +use core::prelude::v1::*;
  267. use io::prelude::*;
  268. -use core::convert::TryInto;
  269. -use cmp;
  270. +#[cfg(feature = "collections")] use core::convert::TryInto;
  271. +use core::cmp;
  272. use io::{self, Initializer, SeekFrom, Error, ErrorKind};
  273. /// A `Cursor` wraps another type and provides it with a
  274. @@ -79,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind};
  275. /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
  276. /// }
  277. /// ```
  278. -#[stable(feature = "rust1", since = "1.0.0")]
  279. #[derive(Clone, Debug)]
  280. pub struct Cursor<T> {
  281. inner: T,
  282. @@ -102,7 +102,6 @@ impl<T> Cursor<T> {
  283. /// # fn force_inference(_: &Cursor<Vec<u8>>) {}
  284. /// # force_inference(&buff);
  285. /// ```
  286. - #[stable(feature = "rust1", since = "1.0.0")]
  287. pub fn new(inner: T) -> Cursor<T> {
  288. Cursor { pos: 0, inner: inner }
  289. }
  290. @@ -120,7 +119,6 @@ impl<T> Cursor<T> {
  291. ///
  292. /// let vec = buff.into_inner();
  293. /// ```
  294. - #[stable(feature = "rust1", since = "1.0.0")]
  295. pub fn into_inner(self) -> T { self.inner }
  296. /// Gets a reference to the underlying value in this cursor.
  297. @@ -136,7 +134,6 @@ impl<T> Cursor<T> {
  298. ///
  299. /// let reference = buff.get_ref();
  300. /// ```
  301. - #[stable(feature = "rust1", since = "1.0.0")]
  302. pub fn get_ref(&self) -> &T { &self.inner }
  303. /// Gets a mutable reference to the underlying value in this cursor.
  304. @@ -155,7 +152,6 @@ impl<T> Cursor<T> {
  305. ///
  306. /// let reference = buff.get_mut();
  307. /// ```
  308. - #[stable(feature = "rust1", since = "1.0.0")]
  309. pub fn get_mut(&mut self) -> &mut T { &mut self.inner }
  310. /// Returns the current position of this cursor.
  311. @@ -177,7 +173,6 @@ impl<T> Cursor<T> {
  312. /// buff.seek(SeekFrom::Current(-1)).unwrap();
  313. /// assert_eq!(buff.position(), 1);
  314. /// ```
  315. - #[stable(feature = "rust1", since = "1.0.0")]
  316. pub fn position(&self) -> u64 { self.pos }
  317. /// Sets the position of this cursor.
  318. @@ -197,11 +192,9 @@ impl<T> Cursor<T> {
  319. /// buff.set_position(4);
  320. /// assert_eq!(buff.position(), 4);
  321. /// ```
  322. - #[stable(feature = "rust1", since = "1.0.0")]
  323. pub fn set_position(&mut self, pos: u64) { self.pos = pos; }
  324. }
  325. -#[stable(feature = "rust1", since = "1.0.0")]
  326. impl<T> io::Seek for Cursor<T> where T: AsRef<[u8]> {
  327. fn seek(&mut self, style: SeekFrom) -> io::Result<u64> {
  328. let (base_pos, offset) = match style {
  329. @@ -222,10 +215,9 @@ impl<T> io::Seek for Cursor<T> where T: AsRef<[u8]> {
  330. }
  331. }
  332. -#[stable(feature = "rust1", since = "1.0.0")]
  333. impl<T> Read for Cursor<T> where T: AsRef<[u8]> {
  334. fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
  335. - let n = Read::read(&mut self.fill_buf()?, buf)?;
  336. + let n = Read::read(&mut self.get_buf()?, buf)?;
  337. self.pos += n as u64;
  338. Ok(n)
  339. }
  340. @@ -236,16 +228,19 @@ impl<T> Read for Cursor<T> where T: AsRef<[u8]> {
  341. }
  342. }
  343. -#[stable(feature = "rust1", since = "1.0.0")]
  344. -impl<T> BufRead for Cursor<T> where T: AsRef<[u8]> {
  345. - fn fill_buf(&mut self) -> io::Result<&[u8]> {
  346. +impl<T> Cursor<T> where T: AsRef<[u8]> {
  347. + fn get_buf(&mut self) -> io::Result<&[u8]> {
  348. let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64);
  349. Ok(&self.inner.as_ref()[(amt as usize)..])
  350. }
  351. +}
  352. +
  353. +#[cfg(feature="collections")]
  354. +impl<T> BufRead for Cursor<T> where T: AsRef<[u8]> {
  355. + fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() }
  356. fn consume(&mut self, amt: usize) { self.pos += amt as u64; }
  357. }
  358. -#[stable(feature = "rust1", since = "1.0.0")]
  359. impl<'a> Write for Cursor<&'a mut [u8]> {
  360. #[inline]
  361. fn write(&mut self, data: &[u8]) -> io::Result<usize> {
  362. @@ -257,7 +252,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> {
  363. fn flush(&mut self) -> io::Result<()> { Ok(()) }
  364. }
  365. -#[stable(feature = "rust1", since = "1.0.0")]
  366. +#[cfg(feature = "collections")]
  367. impl Write for Cursor<Vec<u8>> {
  368. fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
  369. let pos: usize = self.position().try_into().map_err(|_| {
  370. @@ -287,8 +282,8 @@ impl Write for Cursor<Vec<u8>> {
  371. fn flush(&mut self) -> io::Result<()> { Ok(()) }
  372. }
  373. -#[stable(feature = "cursor_box_slice", since = "1.5.0")]
  374. -impl Write for Cursor<Box<[u8]>> {
  375. +#[cfg(feature = "alloc")]
  376. +impl Write for Cursor<::alloc::boxed::Box<[u8]>> {
  377. #[inline]
  378. fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
  379. let pos = cmp::min(self.pos, self.inner.len() as u64);
  380. diff --git a/error.rs b/error.rs
  381. index 0a5804a..4564ca7 100644
  382. --- a/error.rs
  383. +++ b/error.rs
  384. @@ -8,11 +8,16 @@
  385. // option. This file may not be copied, modified, or distributed
  386. // except according to those terms.
  387. -use error;
  388. -use fmt;
  389. -use result;
  390. -use sys;
  391. -use convert::From;
  392. +#[cfg(feature="alloc")] use alloc::boxed::Box;
  393. +#[cfg(not(feature="alloc"))] use ::FakeBox as Box;
  394. +use core::convert::Into;
  395. +use core::fmt;
  396. +use core::marker::{Send, Sync};
  397. +use core::option::Option::{self, Some, None};
  398. +use core::result;
  399. +#[cfg(feature="collections")] use collections::string::String;
  400. +#[cfg(not(feature="collections"))] use ::ErrorString as String;
  401. +use core::convert::From;
  402. /// A specialized [`Result`](../result/enum.Result.html) type for I/O
  403. /// operations.
  404. @@ -44,7 +49,6 @@ use convert::From;
  405. /// Ok(buffer)
  406. /// }
  407. /// ```
  408. -#[stable(feature = "rust1", since = "1.0.0")]
  409. pub type Result<T> = result::Result<T, Error>;
  410. /// The error type for I/O operations of the `Read`, `Write`, `Seek`, and
  411. @@ -56,7 +60,6 @@ pub type Result<T> = result::Result<T, Error>;
  412. ///
  413. /// [`ErrorKind`]: enum.ErrorKind.html
  414. #[derive(Debug)]
  415. -#[stable(feature = "rust1", since = "1.0.0")]
  416. pub struct Error {
  417. repr: Repr,
  418. }
  419. @@ -64,13 +67,16 @@ pub struct Error {
  420. enum Repr {
  421. Os(i32),
  422. Simple(ErrorKind),
  423. + #[cfg(feature="alloc")]
  424. Custom(Box<Custom>),
  425. + #[cfg(not(feature="alloc"))]
  426. + Custom(Custom),
  427. }
  428. #[derive(Debug)]
  429. struct Custom {
  430. kind: ErrorKind,
  431. - error: Box<error::Error+Send+Sync>,
  432. + error: String,
  433. }
  434. /// A list specifying general categories of I/O error.
  435. @@ -82,47 +88,34 @@ struct Custom {
  436. ///
  437. /// [`io::Error`]: struct.Error.html
  438. #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
  439. -#[stable(feature = "rust1", since = "1.0.0")]
  440. #[allow(deprecated)]
  441. pub enum ErrorKind {
  442. /// An entity was not found, often a file.
  443. - #[stable(feature = "rust1", since = "1.0.0")]
  444. NotFound,
  445. /// The operation lacked the necessary privileges to complete.
  446. - #[stable(feature = "rust1", since = "1.0.0")]
  447. PermissionDenied,
  448. /// The connection was refused by the remote server.
  449. - #[stable(feature = "rust1", since = "1.0.0")]
  450. ConnectionRefused,
  451. /// The connection was reset by the remote server.
  452. - #[stable(feature = "rust1", since = "1.0.0")]
  453. ConnectionReset,
  454. /// The connection was aborted (terminated) by the remote server.
  455. - #[stable(feature = "rust1", since = "1.0.0")]
  456. ConnectionAborted,
  457. /// The network operation failed because it was not connected yet.
  458. - #[stable(feature = "rust1", since = "1.0.0")]
  459. NotConnected,
  460. /// A socket address could not be bound because the address is already in
  461. /// use elsewhere.
  462. - #[stable(feature = "rust1", since = "1.0.0")]
  463. AddrInUse,
  464. /// A nonexistent interface was requested or the requested address was not
  465. /// local.
  466. - #[stable(feature = "rust1", since = "1.0.0")]
  467. AddrNotAvailable,
  468. /// The operation failed because a pipe was closed.
  469. - #[stable(feature = "rust1", since = "1.0.0")]
  470. BrokenPipe,
  471. /// An entity already exists, often a file.
  472. - #[stable(feature = "rust1", since = "1.0.0")]
  473. AlreadyExists,
  474. /// The operation needs to block to complete, but the blocking operation was
  475. /// requested to not occur.
  476. - #[stable(feature = "rust1", since = "1.0.0")]
  477. WouldBlock,
  478. /// A parameter was incorrect.
  479. - #[stable(feature = "rust1", since = "1.0.0")]
  480. InvalidInput,
  481. /// Data not valid for the operation were encountered.
  482. ///
  483. @@ -134,10 +127,8 @@ pub enum ErrorKind {
  484. /// `InvalidData` if the file's contents are not valid UTF-8.
  485. ///
  486. /// [`InvalidInput`]: #variant.InvalidInput
  487. - #[stable(feature = "io_invalid_data", since = "1.2.0")]
  488. InvalidData,
  489. /// The I/O operation's timeout expired, causing it to be canceled.
  490. - #[stable(feature = "rust1", since = "1.0.0")]
  491. TimedOut,
  492. /// An error returned when an operation could not be completed because a
  493. /// call to [`write`] returned [`Ok(0)`].
  494. @@ -148,15 +139,12 @@ pub enum ErrorKind {
  495. ///
  496. /// [`write`]: ../../std/io/trait.Write.html#tymethod.write
  497. /// [`Ok(0)`]: ../../std/io/type.Result.html
  498. - #[stable(feature = "rust1", since = "1.0.0")]
  499. WriteZero,
  500. /// This operation was interrupted.
  501. ///
  502. /// Interrupted operations can typically be retried.
  503. - #[stable(feature = "rust1", since = "1.0.0")]
  504. Interrupted,
  505. /// Any I/O error not part of this list.
  506. - #[stable(feature = "rust1", since = "1.0.0")]
  507. Other,
  508. /// An error returned when an operation could not be completed because an
  509. @@ -165,15 +153,10 @@ pub enum ErrorKind {
  510. /// This typically means that an operation could only succeed if it read a
  511. /// particular number of bytes but only a smaller number of bytes could be
  512. /// read.
  513. - #[stable(feature = "read_exact", since = "1.6.0")]
  514. UnexpectedEof,
  515. /// A marker variant that tells the compiler that users of this enum cannot
  516. /// match it exhaustively.
  517. - #[unstable(feature = "io_error_internals",
  518. - reason = "better expressed through extensible enums that this \
  519. - enum cannot be exhaustively matched against",
  520. - issue = "0")]
  521. #[doc(hidden)]
  522. __Nonexhaustive,
  523. }
  524. @@ -206,7 +189,6 @@ impl ErrorKind {
  525. /// Intended for use for errors not exposed to the user, where allocating onto
  526. /// the heap (for normal construction via Error::new) is too costly.
  527. -#[stable(feature = "io_error_from_errorkind", since = "1.14.0")]
  528. impl From<ErrorKind> for Error {
  529. #[inline]
  530. fn from(kind: ErrorKind) -> Error {
  531. @@ -235,14 +217,13 @@ impl Error {
  532. /// // errors can also be created from other errors
  533. /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error);
  534. /// ```
  535. - #[stable(feature = "rust1", since = "1.0.0")]
  536. pub fn new<E>(kind: ErrorKind, error: E) -> Error
  537. - where E: Into<Box<error::Error+Send+Sync>>
  538. + where E: Into<String>
  539. {
  540. Self::_new(kind, error.into())
  541. }
  542. - fn _new(kind: ErrorKind, error: Box<error::Error+Send+Sync>) -> Error {
  543. + fn _new(kind: ErrorKind, error: String) -> Error {
  544. Error {
  545. repr: Repr::Custom(Box::new(Custom {
  546. kind: kind,
  547. @@ -251,24 +232,6 @@ impl Error {
  548. }
  549. }
  550. - /// Returns an error representing the last OS error which occurred.
  551. - ///
  552. - /// This function reads the value of `errno` for the target platform (e.g.
  553. - /// `GetLastError` on Windows) and will return a corresponding instance of
  554. - /// `Error` for the error code.
  555. - ///
  556. - /// # Examples
  557. - ///
  558. - /// ```
  559. - /// use std::io::Error;
  560. - ///
  561. - /// println!("last OS error: {:?}", Error::last_os_error());
  562. - /// ```
  563. - #[stable(feature = "rust1", since = "1.0.0")]
  564. - pub fn last_os_error() -> Error {
  565. - Error::from_raw_os_error(sys::os::errno() as i32)
  566. - }
  567. -
  568. /// Creates a new instance of an `Error` from a particular OS error code.
  569. ///
  570. /// # Examples
  571. @@ -294,7 +257,6 @@ impl Error {
  572. /// assert_eq!(error.kind(), io::ErrorKind::AddrInUse);
  573. /// # }
  574. /// ```
  575. - #[stable(feature = "rust1", since = "1.0.0")]
  576. pub fn from_raw_os_error(code: i32) -> Error {
  577. Error { repr: Repr::Os(code) }
  578. }
  579. @@ -325,7 +287,6 @@ impl Error {
  580. /// print_os_error(&Error::new(ErrorKind::Other, "oh no!"));
  581. /// }
  582. /// ```
  583. - #[stable(feature = "rust1", since = "1.0.0")]
  584. pub fn raw_os_error(&self) -> Option<i32> {
  585. match self.repr {
  586. Repr::Os(i) => Some(i),
  587. @@ -359,12 +320,11 @@ impl Error {
  588. /// print_error(&Error::new(ErrorKind::Other, "oh no!"));
  589. /// }
  590. /// ```
  591. - #[stable(feature = "io_error_inner", since = "1.3.0")]
  592. - pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> {
  593. + pub fn get_ref(&self) -> Option<&String> {
  594. match self.repr {
  595. Repr::Os(..) => None,
  596. Repr::Simple(..) => None,
  597. - Repr::Custom(ref c) => Some(&*c.error),
  598. + Repr::Custom(ref c) => Some(&c.error),
  599. }
  600. }
  601. @@ -430,12 +390,11 @@ impl Error {
  602. /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new())));
  603. /// }
  604. /// ```
  605. - #[stable(feature = "io_error_inner", since = "1.3.0")]
  606. - pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> {
  607. + pub fn get_mut(&mut self) -> Option<&mut String> {
  608. match self.repr {
  609. Repr::Os(..) => None,
  610. Repr::Simple(..) => None,
  611. - Repr::Custom(ref mut c) => Some(&mut *c.error),
  612. + Repr::Custom(ref mut c) => Some(&mut c.error),
  613. }
  614. }
  615. @@ -464,8 +423,7 @@ impl Error {
  616. /// print_error(Error::new(ErrorKind::Other, "oh no!"));
  617. /// }
  618. /// ```
  619. - #[stable(feature = "io_error_inner", since = "1.3.0")]
  620. - pub fn into_inner(self) -> Option<Box<error::Error+Send+Sync>> {
  621. + pub fn into_inner(self) -> Option<String> {
  622. match self.repr {
  623. Repr::Os(..) => None,
  624. Repr::Simple(..) => None,
  625. @@ -491,10 +449,9 @@ impl Error {
  626. /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!"));
  627. /// }
  628. /// ```
  629. - #[stable(feature = "rust1", since = "1.0.0")]
  630. pub fn kind(&self) -> ErrorKind {
  631. match self.repr {
  632. - Repr::Os(code) => sys::decode_error_kind(code),
  633. + Repr::Os(_code) => ErrorKind::Other,
  634. Repr::Custom(ref c) => c.kind,
  635. Repr::Simple(kind) => kind,
  636. }
  637. @@ -505,21 +462,18 @@ impl fmt::Debug for Repr {
  638. fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
  639. match *self {
  640. Repr::Os(ref code) =>
  641. - fmt.debug_struct("Os").field("code", code)
  642. - .field("message", &sys::os::error_string(*code)).finish(),
  643. + fmt.debug_struct("Os").field("code", code).finish(),
  644. Repr::Custom(ref c) => fmt.debug_tuple("Custom").field(c).finish(),
  645. Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(),
  646. }
  647. }
  648. }
  649. -#[stable(feature = "rust1", since = "1.0.0")]
  650. impl fmt::Display for Error {
  651. fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
  652. match self.repr {
  653. Repr::Os(code) => {
  654. - let detail = sys::os::error_string(code);
  655. - write!(fmt, "{} (os error {})", detail, code)
  656. + write!(fmt, "os error {}", code)
  657. }
  658. Repr::Custom(ref c) => c.error.fmt(fmt),
  659. Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()),
  660. @@ -527,24 +481,6 @@ impl fmt::Display for Error {
  661. }
  662. }
  663. -#[stable(feature = "rust1", since = "1.0.0")]
  664. -impl error::Error for Error {
  665. - fn description(&self) -> &str {
  666. - match self.repr {
  667. - Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(),
  668. - Repr::Custom(ref c) => c.error.description(),
  669. - }
  670. - }
  671. -
  672. - fn cause(&self) -> Option<&error::Error> {
  673. - match self.repr {
  674. - Repr::Os(..) => None,
  675. - Repr::Simple(..) => None,
  676. - Repr::Custom(ref c) => c.error.cause(),
  677. - }
  678. - }
  679. -}
  680. -
  681. fn _assert_error_is_sync_send() {
  682. fn _is_sync_send<T: Sync+Send>() {}
  683. _is_sync_send::<Error>();
  684. diff --git a/impls.rs b/impls.rs
  685. index d6b41ce..1ddabf1 100644
  686. --- a/impls.rs
  687. +++ b/impls.rs
  688. @@ -8,15 +8,18 @@
  689. // option. This file may not be copied, modified, or distributed
  690. // except according to those terms.
  691. -use cmp;
  692. -use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind};
  693. -use fmt;
  694. -use mem;
  695. +#[cfg(feature="alloc")] use alloc::boxed::Box;
  696. +use core::cmp;
  697. +use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind};
  698. +#[cfg(feature="collections")] use io::BufRead;
  699. +use core::fmt;
  700. +use core::mem;
  701. +#[cfg(feature="collections")] use collections::string::String;
  702. +#[cfg(feature="collections")] use collections::vec::Vec;
  703. // =============================================================================
  704. // Forwarding implementations
  705. -#[stable(feature = "rust1", since = "1.0.0")]
  706. impl<'a, R: Read + ?Sized> Read for &'a mut R {
  707. #[inline]
  708. fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
  709. @@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R {
  710. (**self).initializer()
  711. }
  712. + #[cfg(feature="collections")]
  713. #[inline]
  714. fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
  715. (**self).read_to_end(buf)
  716. }
  717. + #[cfg(feature="collections")]
  718. #[inline]
  719. fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
  720. (**self).read_to_string(buf)
  721. @@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R {
  722. (**self).read_exact(buf)
  723. }
  724. }
  725. -#[stable(feature = "rust1", since = "1.0.0")]
  726. impl<'a, W: Write + ?Sized> Write for &'a mut W {
  727. #[inline]
  728. fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (**self).write(buf) }
  729. @@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W {
  730. (**self).write_fmt(fmt)
  731. }
  732. }
  733. -#[stable(feature = "rust1", since = "1.0.0")]
  734. impl<'a, S: Seek + ?Sized> Seek for &'a mut S {
  735. #[inline]
  736. fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { (**self).seek(pos) }
  737. }
  738. -#[stable(feature = "rust1", since = "1.0.0")]
  739. +#[cfg(feature="collections")]
  740. impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B {
  741. #[inline]
  742. fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() }
  743. @@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B {
  744. }
  745. }
  746. -#[stable(feature = "rust1", since = "1.0.0")]
  747. +#[cfg(feature="alloc")]
  748. impl<R: Read + ?Sized> Read for Box<R> {
  749. #[inline]
  750. fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
  751. @@ -97,11 +100,13 @@ impl<R: Read + ?Sized> Read for Box<R> {
  752. (**self).initializer()
  753. }
  754. + #[cfg(feature="collections")]
  755. #[inline]
  756. fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
  757. (**self).read_to_end(buf)
  758. }
  759. + #[cfg(feature="collections")]
  760. #[inline]
  761. fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
  762. (**self).read_to_string(buf)
  763. @@ -112,7 +117,7 @@ impl<R: Read + ?Sized> Read for Box<R> {
  764. (**self).read_exact(buf)
  765. }
  766. }
  767. -#[stable(feature = "rust1", since = "1.0.0")]
  768. +#[cfg(feature="alloc")]
  769. impl<W: Write + ?Sized> Write for Box<W> {
  770. #[inline]
  771. fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (**self).write(buf) }
  772. @@ -130,12 +135,12 @@ impl<W: Write + ?Sized> Write for Box<W> {
  773. (**self).write_fmt(fmt)
  774. }
  775. }
  776. -#[stable(feature = "rust1", since = "1.0.0")]
  777. +#[cfg(feature="alloc")]
  778. impl<S: Seek + ?Sized> Seek for Box<S> {
  779. #[inline]
  780. fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { (**self).seek(pos) }
  781. }
  782. -#[stable(feature = "rust1", since = "1.0.0")]
  783. +#[cfg(feature="collections")]
  784. impl<B: BufRead + ?Sized> BufRead for Box<B> {
  785. #[inline]
  786. fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() }
  787. @@ -161,7 +166,6 @@ impl<B: BufRead + ?Sized> BufRead for Box<B> {
  788. ///
  789. /// Note that reading updates the slice to point to the yet unread part.
  790. /// The slice will be empty when EOF is reached.
  791. -#[stable(feature = "rust1", since = "1.0.0")]
  792. impl<'a> Read for &'a [u8] {
  793. #[inline]
  794. fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
  795. @@ -208,7 +212,7 @@ impl<'a> Read for &'a [u8] {
  796. }
  797. }
  798. -#[stable(feature = "rust1", since = "1.0.0")]
  799. +#[cfg(feature="collections")]
  800. impl<'a> BufRead for &'a [u8] {
  801. #[inline]
  802. fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) }
  803. @@ -222,7 +226,6 @@ impl<'a> BufRead for &'a [u8] {
  804. ///
  805. /// Note that writing updates the slice to point to the yet unwritten part.
  806. /// The slice will be empty when it has been completely overwritten.
  807. -#[stable(feature = "rust1", since = "1.0.0")]
  808. impl<'a> Write for &'a mut [u8] {
  809. #[inline]
  810. fn write(&mut self, data: &[u8]) -> io::Result<usize> {
  811. @@ -248,7 +251,7 @@ impl<'a> Write for &'a mut [u8] {
  812. /// Write is implemented for `Vec<u8>` by appending to the vector.
  813. /// The vector will grow as needed.
  814. -#[stable(feature = "rust1", since = "1.0.0")]
  815. +#[cfg(feature="collections")]
  816. impl Write for Vec<u8> {
  817. #[inline]
  818. fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
  819. diff --git a/memchr.rs b/memchr.rs
  820. index 3824a5f..312cf47 100644
  821. --- a/memchr.rs
  822. +++ b/memchr.rs
  823. @@ -11,10 +11,12 @@
  824. // Original implementation taken from rust-memchr
  825. // Copyright 2015 Andrew Gallant, bluss and Nicolas Koch
  826. +pub use self::fallback::{memchr,memrchr};
  827. +
  828. #[allow(dead_code)]
  829. pub mod fallback {
  830. - use cmp;
  831. - use mem;
  832. + use core::cmp;
  833. + use core::mem;
  834. const LO_U64: u64 = 0x0101010101010101;
  835. const HI_U64: u64 = 0x8080808080808080;
  836. diff --git a/mod.rs b/mod.rs
  837. index 71c7600..ab9da6e 100644
  838. --- a/mod.rs
  839. +++ b/mod.rs
  840. @@ -266,50 +266,35 @@
  841. //! [`?` operator]: ../../book/first-edition/syntax-index.html
  842. //! [`Read::read`]: trait.Read.html#tymethod.read
  843. -#![stable(feature = "rust1", since = "1.0.0")]
  844. -
  845. -use cmp;
  846. +use core::cmp;
  847. use core::str as core_str;
  848. -use error as std_error;
  849. -use fmt;
  850. -use result;
  851. -use str;
  852. -use memchr;
  853. -use ptr;
  854. -
  855. -#[stable(feature = "rust1", since = "1.0.0")]
  856. -pub use self::buffered::{BufReader, BufWriter, LineWriter};
  857. -#[stable(feature = "rust1", since = "1.0.0")]
  858. -pub use self::buffered::IntoInnerError;
  859. -#[stable(feature = "rust1", since = "1.0.0")]
  860. +use core::fmt;
  861. +use core::result;
  862. +#[cfg(feature="collections")] use collections::string::String;
  863. +use core::str;
  864. +#[cfg(feature="collections")] use collections::vec::Vec;
  865. +mod memchr;
  866. +use core::ptr;
  867. +
  868. +#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter};
  869. +#[cfg(feature="collections")] pub use self::buffered::IntoInnerError;
  870. pub use self::cursor::Cursor;
  871. -#[stable(feature = "rust1", since = "1.0.0")]
  872. pub use self::error::{Result, Error, ErrorKind};
  873. -#[stable(feature = "rust1", since = "1.0.0")]
  874. pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat};
  875. -#[stable(feature = "rust1", since = "1.0.0")]
  876. -pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr};
  877. -#[stable(feature = "rust1", since = "1.0.0")]
  878. -pub use self::stdio::{StdoutLock, StderrLock, StdinLock};
  879. -#[unstable(feature = "print_internals", issue = "0")]
  880. -pub use self::stdio::{_print, _eprint};
  881. -#[unstable(feature = "libstd_io_internals", issue = "42788")]
  882. -#[doc(no_inline, hidden)]
  883. -pub use self::stdio::{set_panic, set_print};
  884. pub mod prelude;
  885. -mod buffered;
  886. +#[cfg(feature="collections")] mod buffered;
  887. mod cursor;
  888. mod error;
  889. mod impls;
  890. -mod lazy;
  891. mod util;
  892. -mod stdio;
  893. -const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;
  894. +const DEFAULT_BUF_SIZE: usize = 8 * 1024;
  895. +#[cfg(feature="collections")]
  896. struct Guard<'a> { buf: &'a mut Vec<u8>, len: usize }
  897. +#[cfg(feature="collections")]
  898. impl<'a> Drop for Guard<'a> {
  899. fn drop(&mut self) {
  900. unsafe { self.buf.set_len(self.len); }
  901. @@ -334,6 +319,7 @@ impl<'a> Drop for Guard<'a> {
  902. // 2. We're passing a raw buffer to the function `f`, and it is expected that
  903. // the function only *appends* bytes to the buffer. We'll get undefined
  904. // behavior if existing bytes are overwritten to have non-UTF-8 data.
  905. +#[cfg(feature="collections")]
  906. fn append_to_string<F>(buf: &mut String, f: F) -> Result<usize>
  907. where F: FnOnce(&mut Vec<u8>) -> Result<usize>
  908. {
  909. @@ -361,6 +347,7 @@ fn append_to_string<F>(buf: &mut String, f: F) -> Result<usize>
  910. //
  911. // Because we're extending the buffer with uninitialized data for trusted
  912. // readers, we need to make sure to truncate that if any of this panics.
  913. +#[cfg(feature="collections")]
  914. fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize> {
  915. let start_len = buf.len();
  916. let mut g = Guard { len: buf.len(), buf: buf };
  917. @@ -446,7 +433,6 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
  918. /// # Ok(())
  919. /// # }
  920. /// ```
  921. -#[stable(feature = "rust1", since = "1.0.0")]
  922. pub trait Read {
  923. /// Pull some bytes from this source into the specified buffer, returning
  924. /// how many bytes were read.
  925. @@ -499,7 +485,6 @@ pub trait Read {
  926. /// # Ok(())
  927. /// # }
  928. /// ```
  929. - #[stable(feature = "rust1", since = "1.0.0")]
  930. fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
  931. /// Determines if this `Read`er can work with buffers of uninitialized
  932. @@ -521,7 +506,6 @@ pub trait Read {
  933. /// This method is unsafe because a `Read`er could otherwise return a
  934. /// non-zeroing `Initializer` from another `Read` type without an `unsafe`
  935. /// block.
  936. - #[unstable(feature = "read_initializer", issue = "42788")]
  937. #[inline]
  938. unsafe fn initializer(&self) -> Initializer {
  939. Initializer::zeroing()
  940. @@ -566,7 +550,7 @@ pub trait Read {
  941. /// # Ok(())
  942. /// # }
  943. /// ```
  944. - #[stable(feature = "rust1", since = "1.0.0")]
  945. + #[cfg(feature="collections")]
  946. fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> {
  947. read_to_end(self, buf)
  948. }
  949. @@ -604,7 +588,7 @@ pub trait Read {
  950. /// # Ok(())
  951. /// # }
  952. /// ```
  953. - #[stable(feature = "rust1", since = "1.0.0")]
  954. + #[cfg(feature="collections")]
  955. fn read_to_string(&mut self, buf: &mut String) -> Result<usize> {
  956. // Note that we do *not* call `.read_to_end()` here. We are passing
  957. // `&mut Vec<u8>` (the raw contents of `buf`) into the `read_to_end`
  958. @@ -665,7 +649,6 @@ pub trait Read {
  959. /// # Ok(())
  960. /// # }
  961. /// ```
  962. - #[stable(feature = "read_exact", since = "1.6.0")]
  963. fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> {
  964. while !buf.is_empty() {
  965. match self.read(buf) {
  966. @@ -717,7 +700,6 @@ pub trait Read {
  967. /// # Ok(())
  968. /// # }
  969. /// ```
  970. - #[stable(feature = "rust1", since = "1.0.0")]
  971. fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
  972. /// Transforms this `Read` instance to an `Iterator` over its bytes.
  973. @@ -747,7 +729,6 @@ pub trait Read {
  974. /// # Ok(())
  975. /// # }
  976. /// ```
  977. - #[stable(feature = "rust1", since = "1.0.0")]
  978. fn bytes(self) -> Bytes<Self> where Self: Sized {
  979. Bytes { inner: self }
  980. }
  981. @@ -784,10 +765,6 @@ pub trait Read {
  982. /// # Ok(())
  983. /// # }
  984. /// ```
  985. - #[unstable(feature = "io", reason = "the semantics of a partial read/write \
  986. - of where errors happen is currently \
  987. - unclear and may change",
  988. - issue = "27802")]
  989. fn chars(self) -> Chars<Self> where Self: Sized {
  990. Chars { inner: self }
  991. }
  992. @@ -822,7 +799,6 @@ pub trait Read {
  993. /// # Ok(())
  994. /// # }
  995. /// ```
  996. - #[stable(feature = "rust1", since = "1.0.0")]
  997. fn chain<R: Read>(self, next: R) -> Chain<Self, R> where Self: Sized {
  998. Chain { first: self, second: next, done_first: false }
  999. }
  1000. @@ -856,20 +832,17 @@ pub trait Read {
  1001. /// # Ok(())
  1002. /// # }
  1003. /// ```
  1004. - #[stable(feature = "rust1", since = "1.0.0")]
  1005. fn take(self, limit: u64) -> Take<Self> where Self: Sized {
  1006. Take { inner: self, limit: limit }
  1007. }
  1008. }
  1009. /// A type used to conditionally initialize buffers passed to `Read` methods.
  1010. -#[unstable(feature = "read_initializer", issue = "42788")]
  1011. #[derive(Debug)]
  1012. pub struct Initializer(bool);
  1013. impl Initializer {
  1014. /// Returns a new `Initializer` which will zero out buffers.
  1015. - #[unstable(feature = "read_initializer", issue = "42788")]
  1016. #[inline]
  1017. pub fn zeroing() -> Initializer {
  1018. Initializer(true)
  1019. @@ -883,21 +856,18 @@ impl Initializer {
  1020. /// read from buffers passed to `Read` methods, and that the return value of
  1021. /// the method accurately reflects the number of bytes that have been
  1022. /// written to the head of the buffer.
  1023. - #[unstable(feature = "read_initializer", issue = "42788")]
  1024. #[inline]
  1025. pub unsafe fn nop() -> Initializer {
  1026. Initializer(false)
  1027. }
  1028. /// Indicates if a buffer should be initialized.
  1029. - #[unstable(feature = "read_initializer", issue = "42788")]
  1030. #[inline]
  1031. pub fn should_initialize(&self) -> bool {
  1032. self.0
  1033. }
  1034. /// Initializes a buffer if necessary.
  1035. - #[unstable(feature = "read_initializer", issue = "42788")]
  1036. #[inline]
  1037. pub fn initialize(&self, buf: &mut [u8]) {
  1038. if self.should_initialize() {
  1039. @@ -940,7 +910,6 @@ impl Initializer {
  1040. /// # Ok(())
  1041. /// # }
  1042. /// ```
  1043. -#[stable(feature = "rust1", since = "1.0.0")]
  1044. pub trait Write {
  1045. /// Write a buffer into this object, returning how many bytes were written.
  1046. ///
  1047. @@ -984,7 +953,6 @@ pub trait Write {
  1048. /// # Ok(())
  1049. /// # }
  1050. /// ```
  1051. - #[stable(feature = "rust1", since = "1.0.0")]
  1052. fn write(&mut self, buf: &[u8]) -> Result<usize>;
  1053. /// Flush this output stream, ensuring that all intermediately buffered
  1054. @@ -1010,7 +978,6 @@ pub trait Write {
  1055. /// # Ok(())
  1056. /// # }
  1057. /// ```
  1058. - #[stable(feature = "rust1", since = "1.0.0")]
  1059. fn flush(&mut self) -> Result<()>;
  1060. /// Attempts to write an entire buffer into this write.
  1061. @@ -1040,7 +1007,6 @@ pub trait Write {
  1062. /// # Ok(())
  1063. /// # }
  1064. /// ```
  1065. - #[stable(feature = "rust1", since = "1.0.0")]
  1066. fn write_all(&mut self, mut buf: &[u8]) -> Result<()> {
  1067. while !buf.is_empty() {
  1068. match self.write(buf) {
  1069. @@ -1092,7 +1058,6 @@ pub trait Write {
  1070. /// # Ok(())
  1071. /// # }
  1072. /// ```
  1073. - #[stable(feature = "rust1", since = "1.0.0")]
  1074. fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> {
  1075. // Create a shim which translates a Write to a fmt::Write and saves
  1076. // off I/O errors. instead of discarding them
  1077. @@ -1148,7 +1113,6 @@ pub trait Write {
  1078. /// # Ok(())
  1079. /// # }
  1080. /// ```
  1081. - #[stable(feature = "rust1", since = "1.0.0")]
  1082. fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
  1083. }
  1084. @@ -1178,7 +1142,6 @@ pub trait Write {
  1085. /// # Ok(())
  1086. /// # }
  1087. /// ```
  1088. -#[stable(feature = "rust1", since = "1.0.0")]
  1089. pub trait Seek {
  1090. /// Seek to an offset, in bytes, in a stream.
  1091. ///
  1092. @@ -1194,7 +1157,6 @@ pub trait Seek {
  1093. /// Seeking to a negative offset is considered an error.
  1094. ///
  1095. /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start
  1096. - #[stable(feature = "rust1", since = "1.0.0")]
  1097. fn seek(&mut self, pos: SeekFrom) -> Result<u64>;
  1098. }
  1099. @@ -1204,29 +1166,26 @@ pub trait Seek {
  1100. ///
  1101. /// [`Seek`]: trait.Seek.html
  1102. #[derive(Copy, PartialEq, Eq, Clone, Debug)]
  1103. -#[stable(feature = "rust1", since = "1.0.0")]
  1104. pub enum SeekFrom {
  1105. /// Set the offset to the provided number of bytes.
  1106. - #[stable(feature = "rust1", since = "1.0.0")]
  1107. - Start(#[stable(feature = "rust1", since = "1.0.0")] u64),
  1108. + Start(u64),
  1109. /// Set the offset to the size of this object plus the specified number of
  1110. /// bytes.
  1111. ///
  1112. /// It is possible to seek beyond the end of an object, but it's an error to
  1113. /// seek before byte 0.
  1114. - #[stable(feature = "rust1", since = "1.0.0")]
  1115. - End(#[stable(feature = "rust1", since = "1.0.0")] i64),
  1116. + End(i64),
  1117. /// Set the offset to the current position plus the specified number of
  1118. /// bytes.
  1119. ///
  1120. /// It is possible to seek beyond the end of an object, but it's an error to
  1121. /// seek before byte 0.
  1122. - #[stable(feature = "rust1", since = "1.0.0")]
  1123. - Current(#[stable(feature = "rust1", since = "1.0.0")] i64),
  1124. + Current(i64),
  1125. }
  1126. +#[cfg(feature="collections")]
  1127. fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
  1128. -> Result<usize> {
  1129. let mut read = 0;
  1130. @@ -1306,7 +1265,7 @@ fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
  1131. /// # }
  1132. /// ```
  1133. ///
  1134. -#[stable(feature = "rust1", since = "1.0.0")]
  1135. +#[cfg(feature="collections")]
  1136. pub trait BufRead: Read {
  1137. /// Fills the internal buffer of this object, returning the buffer contents.
  1138. ///
  1139. @@ -1351,7 +1310,6 @@ pub trait BufRead: Read {
  1140. /// // ensure the bytes we worked with aren't returned again later
  1141. /// stdin.consume(length);
  1142. /// ```
  1143. - #[stable(feature = "rust1", since = "1.0.0")]
  1144. fn fill_buf(&mut self) -> Result<&[u8]>;
  1145. /// Tells this buffer that `amt` bytes have been consumed from the buffer,
  1146. @@ -1373,7 +1331,6 @@ pub trait BufRead: Read {
  1147. /// that method's example includes an example of `consume()`.
  1148. ///
  1149. /// [`fill_buf`]: #tymethod.fill_buf
  1150. - #[stable(feature = "rust1", since = "1.0.0")]
  1151. fn consume(&mut self, amt: usize);
  1152. /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached.
  1153. @@ -1429,7 +1386,6 @@ pub trait BufRead: Read {
  1154. /// assert_eq!(num_bytes, 0);
  1155. /// assert_eq!(buf, b"");
  1156. /// ```
  1157. - #[stable(feature = "rust1", since = "1.0.0")]
  1158. fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize> {
  1159. read_until(self, byte, buf)
  1160. }
  1161. @@ -1484,7 +1440,6 @@ pub trait BufRead: Read {
  1162. /// assert_eq!(num_bytes, 0);
  1163. /// assert_eq!(buf, "");
  1164. /// ```
  1165. - #[stable(feature = "rust1", since = "1.0.0")]
  1166. fn read_line(&mut self, buf: &mut String) -> Result<usize> {
  1167. // Note that we are not calling the `.read_until` method here, but
  1168. // rather our hardcoded implementation. For more details as to why, see
  1169. @@ -1525,7 +1480,6 @@ pub trait BufRead: Read {
  1170. /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec()));
  1171. /// assert_eq!(split_iter.next(), None);
  1172. /// ```
  1173. - #[stable(feature = "rust1", since = "1.0.0")]
  1174. fn split(self, byte: u8) -> Split<Self> where Self: Sized {
  1175. Split { buf: self, delim: byte }
  1176. }
  1177. @@ -1564,7 +1518,6 @@ pub trait BufRead: Read {
  1178. /// Each line of the iterator has the same error semantics as [`BufRead::read_line`].
  1179. ///
  1180. /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line
  1181. - #[stable(feature = "rust1", since = "1.0.0")]
  1182. fn lines(self) -> Lines<Self> where Self: Sized {
  1183. Lines { buf: self }
  1184. }
  1185. @@ -1576,7 +1529,6 @@ pub trait BufRead: Read {
  1186. /// Please see the documentation of [`chain`] for more details.
  1187. ///
  1188. /// [`chain`]: trait.Read.html#method.chain
  1189. -#[stable(feature = "rust1", since = "1.0.0")]
  1190. pub struct Chain<T, U> {
  1191. first: T,
  1192. second: U,
  1193. @@ -1602,7 +1554,6 @@ impl<T, U> Chain<T, U> {
  1194. /// # Ok(())
  1195. /// # }
  1196. /// ```
  1197. - #[stable(feature = "more_io_inner_methods", since = "1.20.0")]
  1198. pub fn into_inner(self) -> (T, U) {
  1199. (self.first, self.second)
  1200. }
  1201. @@ -1625,7 +1576,6 @@ impl<T, U> Chain<T, U> {
  1202. /// # Ok(())
  1203. /// # }
  1204. /// ```
  1205. - #[stable(feature = "more_io_inner_methods", since = "1.20.0")]
  1206. pub fn get_ref(&self) -> (&T, &U) {
  1207. (&self.first, &self.second)
  1208. }
  1209. @@ -1652,13 +1602,11 @@ impl<T, U> Chain<T, U> {
  1210. /// # Ok(())
  1211. /// # }
  1212. /// ```
  1213. - #[stable(feature = "more_io_inner_methods", since = "1.20.0")]
  1214. pub fn get_mut(&mut self) -> (&mut T, &mut U) {
  1215. (&mut self.first, &mut self.second)
  1216. }
  1217. }
  1218. -#[stable(feature = "std_debug", since = "1.16.0")]
  1219. impl<T: fmt::Debug, U: fmt::Debug> fmt::Debug for Chain<T, U> {
  1220. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  1221. f.debug_struct("Chain")
  1222. @@ -1668,7 +1616,6 @@ impl<T: fmt::Debug, U: fmt::Debug> fmt::Debug for Chain<T, U> {
  1223. }
  1224. }
  1225. -#[stable(feature = "rust1", since = "1.0.0")]
  1226. impl<T: Read, U: Read> Read for Chain<T, U> {
  1227. fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
  1228. if !self.done_first {
  1229. @@ -1690,7 +1637,7 @@ impl<T: Read, U: Read> Read for Chain<T, U> {
  1230. }
  1231. }
  1232. -#[stable(feature = "chain_bufread", since = "1.9.0")]
  1233. +#[cfg(feature="collections")]
  1234. impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
  1235. fn fill_buf(&mut self) -> Result<&[u8]> {
  1236. if !self.done_first {
  1237. @@ -1717,7 +1664,6 @@ impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
  1238. /// Please see the documentation of [`take`] for more details.
  1239. ///
  1240. /// [`take`]: trait.Read.html#method.take
  1241. -#[stable(feature = "rust1", since = "1.0.0")]
  1242. #[derive(Debug)]
  1243. pub struct Take<T> {
  1244. inner: T,
  1245. @@ -1752,7 +1698,6 @@ impl<T> Take<T> {
  1246. /// # Ok(())
  1247. /// # }
  1248. /// ```
  1249. - #[stable(feature = "rust1", since = "1.0.0")]
  1250. pub fn limit(&self) -> u64 { self.limit }
  1251. /// Consumes the `Take`, returning the wrapped reader.
  1252. @@ -1775,7 +1720,6 @@ impl<T> Take<T> {
  1253. /// # Ok(())
  1254. /// # }
  1255. /// ```
  1256. - #[stable(feature = "io_take_into_inner", since = "1.15.0")]
  1257. pub fn into_inner(self) -> T {
  1258. self.inner
  1259. }
  1260. @@ -1800,7 +1744,6 @@ impl<T> Take<T> {
  1261. /// # Ok(())
  1262. /// # }
  1263. /// ```
  1264. - #[stable(feature = "more_io_inner_methods", since = "1.20.0")]
  1265. pub fn get_ref(&self) -> &T {
  1266. &self.inner
  1267. }
  1268. @@ -1829,13 +1772,11 @@ impl<T> Take<T> {
  1269. /// # Ok(())
  1270. /// # }
  1271. /// ```
  1272. - #[stable(feature = "more_io_inner_methods", since = "1.20.0")]
  1273. pub fn get_mut(&mut self) -> &mut T {
  1274. &mut self.inner
  1275. }
  1276. }
  1277. -#[stable(feature = "rust1", since = "1.0.0")]
  1278. impl<T: Read> Read for Take<T> {
  1279. fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
  1280. // Don't call into inner reader at all at EOF because it may still block
  1281. @@ -1854,7 +1795,7 @@ impl<T: Read> Read for Take<T> {
  1282. }
  1283. }
  1284. -#[stable(feature = "rust1", since = "1.0.0")]
  1285. +#[cfg(feature="collections")]
  1286. impl<T: BufRead> BufRead for Take<T> {
  1287. fn fill_buf(&mut self) -> Result<&[u8]> {
  1288. // Don't call into inner reader at all at EOF because it may still block
  1289. @@ -1893,13 +1834,11 @@ fn read_one_byte(reader: &mut Read) -> Option<Result<u8>> {
  1290. /// Please see the documentation of [`bytes`] for more details.
  1291. ///
  1292. /// [`bytes`]: trait.Read.html#method.bytes
  1293. -#[stable(feature = "rust1", since = "1.0.0")]
  1294. #[derive(Debug)]
  1295. pub struct Bytes<R> {
  1296. inner: R,
  1297. }
  1298. -#[stable(feature = "rust1", since = "1.0.0")]
  1299. impl<R: Read> Iterator for Bytes<R> {
  1300. type Item = Result<u8>;
  1301. @@ -1914,8 +1853,6 @@ impl<R: Read> Iterator for Bytes<R> {
  1302. /// Please see the documentation of `chars()` for more details.
  1303. ///
  1304. /// [chars]: trait.Read.html#method.chars
  1305. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1306. - issue = "27802")]
  1307. #[derive(Debug)]
  1308. pub struct Chars<R> {
  1309. inner: R,
  1310. @@ -1924,8 +1861,6 @@ pub struct Chars<R> {
  1311. /// An enumeration of possible errors that can be generated from the `Chars`
  1312. /// adapter.
  1313. #[derive(Debug)]
  1314. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1315. - issue = "27802")]
  1316. pub enum CharsError {
  1317. /// Variant representing that the underlying stream was read successfully
  1318. /// but it did not contain valid utf8 data.
  1319. @@ -1935,8 +1870,6 @@ pub enum CharsError {
  1320. Other(Error),
  1321. }
  1322. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1323. - issue = "27802")]
  1324. impl<R: Read> Iterator for Chars<R> {
  1325. type Item = result::Result<char, CharsError>;
  1326. @@ -1968,25 +1901,6 @@ impl<R: Read> Iterator for Chars<R> {
  1327. }
  1328. }
  1329. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1330. - issue = "27802")]
  1331. -impl std_error::Error for CharsError {
  1332. - fn description(&self) -> &str {
  1333. - match *self {
  1334. - CharsError::NotUtf8 => "invalid utf8 encoding",
  1335. - CharsError::Other(ref e) => std_error::Error::description(e),
  1336. - }
  1337. - }
  1338. - fn cause(&self) -> Option<&std_error::Error> {
  1339. - match *self {
  1340. - CharsError::NotUtf8 => None,
  1341. - CharsError::Other(ref e) => e.cause(),
  1342. - }
  1343. - }
  1344. -}
  1345. -
  1346. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1347. - issue = "27802")]
  1348. impl fmt::Display for CharsError {
  1349. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  1350. match *self {
  1351. @@ -2005,14 +1919,14 @@ impl fmt::Display for CharsError {
  1352. /// `BufRead`. Please see the documentation of `split()` for more details.
  1353. ///
  1354. /// [split]: trait.BufRead.html#method.split
  1355. -#[stable(feature = "rust1", since = "1.0.0")]
  1356. +#[cfg(feature="collections")]
  1357. #[derive(Debug)]
  1358. pub struct Split<B> {
  1359. buf: B,
  1360. delim: u8,
  1361. }
  1362. -#[stable(feature = "rust1", since = "1.0.0")]
  1363. +#[cfg(feature="collections")]
  1364. impl<B: BufRead> Iterator for Split<B> {
  1365. type Item = Result<Vec<u8>>;
  1366. @@ -2037,13 +1951,13 @@ impl<B: BufRead> Iterator for Split<B> {
  1367. /// `BufRead`. Please see the documentation of `lines()` for more details.
  1368. ///
  1369. /// [lines]: trait.BufRead.html#method.lines
  1370. -#[stable(feature = "rust1", since = "1.0.0")]
  1371. +#[cfg(feature="collections")]
  1372. #[derive(Debug)]
  1373. pub struct Lines<B> {
  1374. buf: B,
  1375. }
  1376. -#[stable(feature = "rust1", since = "1.0.0")]
  1377. +#[cfg(feature="collections")]
  1378. impl<B: BufRead> Iterator for Lines<B> {
  1379. type Item = Result<String>;
  1380. diff --git a/prelude.rs b/prelude.rs
  1381. index 8772d0f..49d66c9 100644
  1382. --- a/prelude.rs
  1383. +++ b/prelude.rs
  1384. @@ -18,7 +18,8 @@
  1385. //! use std::io::prelude::*;
  1386. //! ```
  1387. -#![stable(feature = "rust1", since = "1.0.0")]
  1388. +pub use super::{Read, Write, Seek};
  1389. +#[cfg(feature="collections")] pub use super::BufRead;
  1390. -#[stable(feature = "rust1", since = "1.0.0")]
  1391. -pub use super::{Read, Write, BufRead, Seek};
  1392. +#[cfg(feature="collections")] pub use alloc::boxed::Box;
  1393. +#[cfg(feature="collections")] pub use collections::vec::Vec;
  1394. diff --git a/util.rs b/util.rs
  1395. index 88f4214..df974c3 100644
  1396. --- a/util.rs
  1397. +++ b/util.rs
  1398. @@ -10,9 +10,10 @@
  1399. #![allow(missing_copy_implementations)]
  1400. -use fmt;
  1401. -use io::{self, Read, Initializer, Write, ErrorKind, BufRead};
  1402. -use mem;
  1403. +use core::fmt;
  1404. +use io::{self, Read, Initializer, Write, ErrorKind};
  1405. +use core::mem;
  1406. +#[cfg(feature="collections")] use io::BufRead;
  1407. /// Copies the entire contents of a reader into a writer.
  1408. ///
  1409. @@ -44,7 +45,6 @@ use mem;
  1410. /// # Ok(())
  1411. /// # }
  1412. /// ```
  1413. -#[stable(feature = "rust1", since = "1.0.0")]
  1414. pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<u64>
  1415. where R: Read, W: Write
  1416. {
  1417. @@ -73,7 +73,6 @@ pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<
  1418. /// the documentation of `empty()` for more details.
  1419. ///
  1420. /// [empty]: fn.empty.html
  1421. -#[stable(feature = "rust1", since = "1.0.0")]
  1422. pub struct Empty { _priv: () }
  1423. /// Constructs a new handle to an empty reader.
  1424. @@ -91,10 +90,8 @@ pub struct Empty { _priv: () }
  1425. /// io::empty().read_to_string(&mut buffer).unwrap();
  1426. /// assert!(buffer.is_empty());
  1427. /// ```
  1428. -#[stable(feature = "rust1", since = "1.0.0")]
  1429. pub fn empty() -> Empty { Empty { _priv: () } }
  1430. -#[stable(feature = "rust1", since = "1.0.0")]
  1431. impl Read for Empty {
  1432. #[inline]
  1433. fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> { Ok(0) }
  1434. @@ -104,7 +101,8 @@ impl Read for Empty {
  1435. Initializer::nop()
  1436. }
  1437. }
  1438. -#[stable(feature = "rust1", since = "1.0.0")]
  1439. +
  1440. +#[cfg(feature="collections")]
  1441. impl BufRead for Empty {
  1442. #[inline]
  1443. fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) }
  1444. @@ -112,7 +110,6 @@ impl BufRead for Empty {
  1445. fn consume(&mut self, _n: usize) {}
  1446. }
  1447. -#[stable(feature = "std_debug", since = "1.16.0")]
  1448. impl fmt::Debug for Empty {
  1449. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  1450. f.pad("Empty { .. }")
  1451. @@ -125,7 +122,6 @@ impl fmt::Debug for Empty {
  1452. /// see the documentation of `repeat()` for more details.
  1453. ///
  1454. /// [repeat]: fn.repeat.html
  1455. -#[stable(feature = "rust1", since = "1.0.0")]
  1456. pub struct Repeat { byte: u8 }
  1457. /// Creates an instance of a reader that infinitely repeats one byte.
  1458. @@ -142,10 +138,8 @@ pub struct Repeat { byte: u8 }
  1459. /// io::repeat(0b101).read_exact(&mut buffer).unwrap();
  1460. /// assert_eq!(buffer, [0b101, 0b101, 0b101]);
  1461. /// ```
  1462. -#[stable(feature = "rust1", since = "1.0.0")]
  1463. pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } }
  1464. -#[stable(feature = "rust1", since = "1.0.0")]
  1465. impl Read for Repeat {
  1466. #[inline]
  1467. fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
  1468. @@ -161,7 +155,6 @@ impl Read for Repeat {
  1469. }
  1470. }
  1471. -#[stable(feature = "std_debug", since = "1.16.0")]
  1472. impl fmt::Debug for Repeat {
  1473. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  1474. f.pad("Repeat { .. }")
  1475. @@ -174,7 +167,6 @@ impl fmt::Debug for Repeat {
  1476. /// see the documentation of `sink()` for more details.
  1477. ///
  1478. /// [sink]: fn.sink.html
  1479. -#[stable(feature = "rust1", since = "1.0.0")]
  1480. pub struct Sink { _priv: () }
  1481. /// Creates an instance of a writer which will successfully consume all data.
  1482. @@ -191,10 +183,8 @@ pub struct Sink { _priv: () }
  1483. /// let num_bytes = io::sink().write(&buffer).unwrap();
  1484. /// assert_eq!(num_bytes, 5);
  1485. /// ```
  1486. -#[stable(feature = "rust1", since = "1.0.0")]
  1487. pub fn sink() -> Sink { Sink { _priv: () } }
  1488. -#[stable(feature = "rust1", since = "1.0.0")]
  1489. impl Write for Sink {
  1490. #[inline]
  1491. fn write(&mut self, buf: &[u8]) -> io::Result<usize> { Ok(buf.len()) }
  1492. @@ -202,7 +192,6 @@ impl Write for Sink {
  1493. fn flush(&mut self) -> io::Result<()> { Ok(()) }
  1494. }
  1495. -#[stable(feature = "std_debug", since = "1.16.0")]
  1496. impl fmt::Debug for Sink {
  1497. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  1498. f.pad("Sink { .. }")