58557fafae060c500394d5df13cd0cf68170903e.patch 55 KB

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