d52acbe37f69a2ebc9d161c479ed628da1cbea4e.patch 55 KB

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