1f9036872d7ea8bee91f8588e3c4a613c58c76cb.patch 50 KB

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