93969734f6a8f38e95c7038c926ab2504e87dad6.patch 55 KB

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