3be2c3b3092e934bdc2db67d5bdcabd611deca9c.patch 50 KB

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