27ede55414e01f13c6869a8763da207e544cc6ad.patch 56 KB

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