80e2e67f4c6fbbef5e4789df7fc96804e6a84196.patch 57 KB

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