0ca9967af75f7a279dcf4921f119b2602b41dd71.patch 51 KB

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