f0a968eada509f71971e3ece02f8ec91b6f79e8a.patch 57 KB

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