32820c149b4b92aafc5f8d2e48a4265c5d865a1d.patch 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477
  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 ca9452f..4f68be4 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 cd05e6b..d048379 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. @@ -147,7 +152,6 @@ impl<B: BufRead + ?Sized> BufRead for Box<B> {
  788. // =============================================================================
  789. // In-memory buffer implementations
  790. -#[stable(feature = "rust1", since = "1.0.0")]
  791. impl<'a> Read for &'a [u8] {
  792. #[inline]
  793. fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
  794. @@ -171,7 +175,7 @@ impl<'a> Read for &'a [u8] {
  795. }
  796. }
  797. -#[stable(feature = "rust1", since = "1.0.0")]
  798. +#[cfg(feature="collections")]
  799. impl<'a> BufRead for &'a [u8] {
  800. #[inline]
  801. fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) }
  802. @@ -180,7 +184,6 @@ impl<'a> BufRead for &'a [u8] {
  803. fn consume(&mut self, amt: usize) { *self = &self[amt..]; }
  804. }
  805. -#[stable(feature = "rust1", since = "1.0.0")]
  806. impl<'a> Write for &'a mut [u8] {
  807. #[inline]
  808. fn write(&mut self, data: &[u8]) -> io::Result<usize> {
  809. @@ -204,7 +207,7 @@ impl<'a> Write for &'a mut [u8] {
  810. fn flush(&mut self) -> io::Result<()> { Ok(()) }
  811. }
  812. -#[stable(feature = "rust1", since = "1.0.0")]
  813. +#[cfg(feature="collections")]
  814. impl Write for Vec<u8> {
  815. #[inline]
  816. fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
  817. diff --git a/memchr.rs b/memchr.rs
  818. index 3824a5f..312cf47 100644
  819. --- a/memchr.rs
  820. +++ b/memchr.rs
  821. @@ -11,10 +11,12 @@
  822. // Original implementation taken from rust-memchr
  823. // Copyright 2015 Andrew Gallant, bluss and Nicolas Koch
  824. +pub use self::fallback::{memchr,memrchr};
  825. +
  826. #[allow(dead_code)]
  827. pub mod fallback {
  828. - use cmp;
  829. - use mem;
  830. + use core::cmp;
  831. + use core::mem;
  832. const LO_U64: u64 = 0x0101010101010101;
  833. const HI_U64: u64 = 0x8080808080808080;
  834. diff --git a/mod.rs b/mod.rs
  835. index 37c3f70..7232bd1 100644
  836. --- a/mod.rs
  837. +++ b/mod.rs
  838. @@ -252,42 +252,32 @@
  839. //! [`io::Result`]: type.Result.html
  840. //! [`try!`]: ../macro.try.html
  841. -#![stable(feature = "rust1", since = "1.0.0")]
  842. -
  843. -use cmp;
  844. +use core::cmp;
  845. use rustc_unicode::str as core_str;
  846. -use error as std_error;
  847. -use fmt;
  848. -use result;
  849. -use str;
  850. -use memchr;
  851. -
  852. -#[stable(feature = "rust1", since = "1.0.0")]
  853. -pub use self::buffered::{BufReader, BufWriter, LineWriter};
  854. -#[stable(feature = "rust1", since = "1.0.0")]
  855. -pub use self::buffered::IntoInnerError;
  856. -#[stable(feature = "rust1", since = "1.0.0")]
  857. +use core::fmt;
  858. +use core::iter::{Iterator};
  859. +use core::marker::Sized;
  860. +#[cfg(feature="collections")] use core::ops::{Drop, FnOnce};
  861. +use core::option::Option::{self, Some, None};
  862. +use core::result::Result::{Ok, Err};
  863. +use core::result;
  864. +#[cfg(feature="collections")] use collections::string::String;
  865. +use core::str;
  866. +#[cfg(feature="collections")] use collections::vec::Vec;
  867. +mod memchr;
  868. +
  869. +#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter};
  870. +#[cfg(feature="collections")] pub use self::buffered::IntoInnerError;
  871. pub use self::cursor::Cursor;
  872. -#[stable(feature = "rust1", since = "1.0.0")]
  873. pub use self::error::{Result, Error, ErrorKind};
  874. -#[stable(feature = "rust1", since = "1.0.0")]
  875. pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat};
  876. -#[stable(feature = "rust1", since = "1.0.0")]
  877. -pub use self::stdio::{stdin, stdout, stderr, _print, Stdin, Stdout, Stderr};
  878. -#[stable(feature = "rust1", since = "1.0.0")]
  879. -pub use self::stdio::{StdoutLock, StderrLock, StdinLock};
  880. -#[unstable(feature = "libstd_io_internals", issue = "0")]
  881. -#[doc(no_inline, hidden)]
  882. -pub use self::stdio::{set_panic, set_print};
  883. pub mod prelude;
  884. -mod buffered;
  885. +#[cfg(feature="collections")] mod buffered;
  886. mod cursor;
  887. mod error;
  888. mod impls;
  889. -mod lazy;
  890. mod util;
  891. -mod stdio;
  892. const DEFAULT_BUF_SIZE: usize = 8 * 1024;
  893. @@ -309,6 +299,7 @@ const DEFAULT_BUF_SIZE: usize = 8 * 1024;
  894. // 2. We're passing a raw buffer to the function `f`, and it is expected that
  895. // the function only *appends* bytes to the buffer. We'll get undefined
  896. // behavior if existing bytes are overwritten to have non-UTF-8 data.
  897. +#[cfg(feature="collections")]
  898. fn append_to_string<F>(buf: &mut String, f: F) -> Result<usize>
  899. where F: FnOnce(&mut Vec<u8>) -> Result<usize>
  900. {
  901. @@ -340,6 +331,7 @@ fn append_to_string<F>(buf: &mut String, f: F) -> Result<usize>
  902. // of data to return. Simply tacking on an extra DEFAULT_BUF_SIZE space every
  903. // time is 4,500 times (!) slower than this if the reader has a very small
  904. // amount of data to return.
  905. +#[cfg(feature="collections")]
  906. fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize> {
  907. let start_len = buf.len();
  908. let mut len = start_len;
  909. @@ -422,7 +414,6 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
  910. /// # Ok(())
  911. /// # }
  912. /// ```
  913. -#[stable(feature = "rust1", since = "1.0.0")]
  914. pub trait Read {
  915. /// Pull some bytes from this source into the specified buffer, returning
  916. /// how many bytes were read.
  917. @@ -472,7 +463,6 @@ pub trait Read {
  918. /// # Ok(())
  919. /// # }
  920. /// ```
  921. - #[stable(feature = "rust1", since = "1.0.0")]
  922. fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
  923. /// Read all bytes until EOF in this source, placing them into `buf`.
  924. @@ -514,7 +504,7 @@ pub trait Read {
  925. /// # Ok(())
  926. /// # }
  927. /// ```
  928. - #[stable(feature = "rust1", since = "1.0.0")]
  929. + #[cfg(feature="collections")]
  930. fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> {
  931. read_to_end(self, buf)
  932. }
  933. @@ -552,7 +542,7 @@ pub trait Read {
  934. /// # Ok(())
  935. /// # }
  936. /// ```
  937. - #[stable(feature = "rust1", since = "1.0.0")]
  938. + #[cfg(feature="collections")]
  939. fn read_to_string(&mut self, buf: &mut String) -> Result<usize> {
  940. // Note that we do *not* call `.read_to_end()` here. We are passing
  941. // `&mut Vec<u8>` (the raw contents of `buf`) into the `read_to_end`
  942. @@ -613,7 +603,6 @@ pub trait Read {
  943. /// # Ok(())
  944. /// # }
  945. /// ```
  946. - #[stable(feature = "read_exact", since = "1.6.0")]
  947. fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> {
  948. while !buf.is_empty() {
  949. match self.read(buf) {
  950. @@ -665,7 +654,6 @@ pub trait Read {
  951. /// # Ok(())
  952. /// # }
  953. /// ```
  954. - #[stable(feature = "rust1", since = "1.0.0")]
  955. fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
  956. /// Transforms this `Read` instance to an `Iterator` over its bytes.
  957. @@ -695,7 +683,6 @@ pub trait Read {
  958. /// # Ok(())
  959. /// # }
  960. /// ```
  961. - #[stable(feature = "rust1", since = "1.0.0")]
  962. fn bytes(self) -> Bytes<Self> where Self: Sized {
  963. Bytes { inner: self }
  964. }
  965. @@ -732,10 +719,6 @@ pub trait Read {
  966. /// # Ok(())
  967. /// # }
  968. /// ```
  969. - #[unstable(feature = "io", reason = "the semantics of a partial read/write \
  970. - of where errors happen is currently \
  971. - unclear and may change",
  972. - issue = "27802")]
  973. fn chars(self) -> Chars<Self> where Self: Sized {
  974. Chars { inner: self }
  975. }
  976. @@ -770,7 +753,6 @@ pub trait Read {
  977. /// # Ok(())
  978. /// # }
  979. /// ```
  980. - #[stable(feature = "rust1", since = "1.0.0")]
  981. fn chain<R: Read>(self, next: R) -> Chain<Self, R> where Self: Sized {
  982. Chain { first: self, second: next, done_first: false }
  983. }
  984. @@ -804,7 +786,6 @@ pub trait Read {
  985. /// # Ok(())
  986. /// # }
  987. /// ```
  988. - #[stable(feature = "rust1", since = "1.0.0")]
  989. fn take(self, limit: u64) -> Take<Self> where Self: Sized {
  990. Take { inner: self, limit: limit }
  991. }
  992. @@ -840,7 +821,6 @@ pub trait Read {
  993. /// # Ok(())
  994. /// # }
  995. /// ```
  996. -#[stable(feature = "rust1", since = "1.0.0")]
  997. pub trait Write {
  998. /// Write a buffer into this object, returning how many bytes were written.
  999. ///
  1000. @@ -880,7 +860,6 @@ pub trait Write {
  1001. /// # Ok(())
  1002. /// # }
  1003. /// ```
  1004. - #[stable(feature = "rust1", since = "1.0.0")]
  1005. fn write(&mut self, buf: &[u8]) -> Result<usize>;
  1006. /// Flush this output stream, ensuring that all intermediately buffered
  1007. @@ -906,7 +885,6 @@ pub trait Write {
  1008. /// # Ok(())
  1009. /// # }
  1010. /// ```
  1011. - #[stable(feature = "rust1", since = "1.0.0")]
  1012. fn flush(&mut self) -> Result<()>;
  1013. /// Attempts to write an entire buffer into this write.
  1014. @@ -933,7 +911,6 @@ pub trait Write {
  1015. /// # Ok(())
  1016. /// # }
  1017. /// ```
  1018. - #[stable(feature = "rust1", since = "1.0.0")]
  1019. fn write_all(&mut self, mut buf: &[u8]) -> Result<()> {
  1020. while !buf.is_empty() {
  1021. match self.write(buf) {
  1022. @@ -985,7 +962,6 @@ pub trait Write {
  1023. /// # Ok(())
  1024. /// # }
  1025. /// ```
  1026. - #[stable(feature = "rust1", since = "1.0.0")]
  1027. fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> {
  1028. // Create a shim which translates a Write to a fmt::Write and saves
  1029. // off I/O errors. instead of discarding them
  1030. @@ -1041,7 +1017,6 @@ pub trait Write {
  1031. /// # Ok(())
  1032. /// # }
  1033. /// ```
  1034. - #[stable(feature = "rust1", since = "1.0.0")]
  1035. fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
  1036. }
  1037. @@ -1071,7 +1046,6 @@ pub trait Write {
  1038. /// # Ok(())
  1039. /// # }
  1040. /// ```
  1041. -#[stable(feature = "rust1", since = "1.0.0")]
  1042. pub trait Seek {
  1043. /// Seek to an offset, in bytes, in a stream.
  1044. ///
  1045. @@ -1087,7 +1061,6 @@ pub trait Seek {
  1046. /// Seeking to a negative offset is considered an error.
  1047. ///
  1048. /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start
  1049. - #[stable(feature = "rust1", since = "1.0.0")]
  1050. fn seek(&mut self, pos: SeekFrom) -> Result<u64>;
  1051. }
  1052. @@ -1097,29 +1070,26 @@ pub trait Seek {
  1053. ///
  1054. /// [`Seek`]: trait.Seek.html
  1055. #[derive(Copy, PartialEq, Eq, Clone, Debug)]
  1056. -#[stable(feature = "rust1", since = "1.0.0")]
  1057. pub enum SeekFrom {
  1058. /// Set the offset to the provided number of bytes.
  1059. - #[stable(feature = "rust1", since = "1.0.0")]
  1060. - Start(#[stable(feature = "rust1", since = "1.0.0")] u64),
  1061. + Start(u64),
  1062. /// Set the offset to the size of this object plus the specified number of
  1063. /// bytes.
  1064. ///
  1065. /// It is possible to seek beyond the end of an object, but it's an error to
  1066. /// seek before byte 0.
  1067. - #[stable(feature = "rust1", since = "1.0.0")]
  1068. - End(#[stable(feature = "rust1", since = "1.0.0")] i64),
  1069. + End(i64),
  1070. /// Set the offset to the current position plus the specified number of
  1071. /// bytes.
  1072. ///
  1073. /// It is possible to seek beyond the end of an object, but it's an error to
  1074. /// seek before byte 0.
  1075. - #[stable(feature = "rust1", since = "1.0.0")]
  1076. - Current(#[stable(feature = "rust1", since = "1.0.0")] i64),
  1077. + Current(i64),
  1078. }
  1079. +#[cfg(feature="collections")]
  1080. fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
  1081. -> Result<usize> {
  1082. let mut read = 0;
  1083. @@ -1199,7 +1169,7 @@ fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
  1084. /// # }
  1085. /// ```
  1086. ///
  1087. -#[stable(feature = "rust1", since = "1.0.0")]
  1088. +#[cfg(feature="collections")]
  1089. pub trait BufRead: Read {
  1090. /// Fills the internal buffer of this object, returning the buffer contents.
  1091. ///
  1092. @@ -1244,7 +1214,6 @@ pub trait BufRead: Read {
  1093. /// // ensure the bytes we worked with aren't returned again later
  1094. /// stdin.consume(length);
  1095. /// ```
  1096. - #[stable(feature = "rust1", since = "1.0.0")]
  1097. fn fill_buf(&mut self) -> Result<&[u8]>;
  1098. /// Tells this buffer that `amt` bytes have been consumed from the buffer,
  1099. @@ -1266,7 +1235,6 @@ pub trait BufRead: Read {
  1100. /// that method's example includes an example of `consume()`.
  1101. ///
  1102. /// [`fill_buf()`]: #tymethod.fill_buf
  1103. - #[stable(feature = "rust1", since = "1.0.0")]
  1104. fn consume(&mut self, amt: usize);
  1105. /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached.
  1106. @@ -1308,7 +1276,6 @@ pub trait BufRead: Read {
  1107. /// # Ok(())
  1108. /// # }
  1109. /// ```
  1110. - #[stable(feature = "rust1", since = "1.0.0")]
  1111. fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize> {
  1112. read_until(self, byte, buf)
  1113. }
  1114. @@ -1355,7 +1322,6 @@ pub trait BufRead: Read {
  1115. /// buffer.clear();
  1116. /// }
  1117. /// ```
  1118. - #[stable(feature = "rust1", since = "1.0.0")]
  1119. fn read_line(&mut self, buf: &mut String) -> Result<usize> {
  1120. // Note that we are not calling the `.read_until` method here, but
  1121. // rather our hardcoded implementation. For more details as to why, see
  1122. @@ -1392,7 +1358,6 @@ pub trait BufRead: Read {
  1123. /// println!("{:?}", content.unwrap());
  1124. /// }
  1125. /// ```
  1126. - #[stable(feature = "rust1", since = "1.0.0")]
  1127. fn split(self, byte: u8) -> Split<Self> where Self: Sized {
  1128. Split { buf: self, delim: byte }
  1129. }
  1130. @@ -1420,7 +1385,6 @@ pub trait BufRead: Read {
  1131. /// println!("{}", line.unwrap());
  1132. /// }
  1133. /// ```
  1134. - #[stable(feature = "rust1", since = "1.0.0")]
  1135. fn lines(self) -> Lines<Self> where Self: Sized {
  1136. Lines { buf: self }
  1137. }
  1138. @@ -1432,14 +1396,12 @@ pub trait BufRead: Read {
  1139. /// Please see the documentation of [`chain()`] for more details.
  1140. ///
  1141. /// [`chain()`]: trait.Read.html#method.chain
  1142. -#[stable(feature = "rust1", since = "1.0.0")]
  1143. pub struct Chain<T, U> {
  1144. first: T,
  1145. second: U,
  1146. done_first: bool,
  1147. }
  1148. -#[stable(feature = "rust1", since = "1.0.0")]
  1149. impl<T: Read, U: Read> Read for Chain<T, U> {
  1150. fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
  1151. if !self.done_first {
  1152. @@ -1452,7 +1414,7 @@ impl<T: Read, U: Read> Read for Chain<T, U> {
  1153. }
  1154. }
  1155. -#[stable(feature = "chain_bufread", since = "1.9.0")]
  1156. +#[cfg(feature="collections")]
  1157. impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
  1158. fn fill_buf(&mut self) -> Result<&[u8]> {
  1159. if !self.done_first {
  1160. @@ -1479,7 +1441,6 @@ impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
  1161. /// Please see the documentation of `take()` for more details.
  1162. ///
  1163. /// [take]: trait.Read.html#method.take
  1164. -#[stable(feature = "rust1", since = "1.0.0")]
  1165. pub struct Take<T> {
  1166. inner: T,
  1167. limit: u64,
  1168. @@ -1511,7 +1472,6 @@ impl<T> Take<T> {
  1169. /// # Ok(())
  1170. /// # }
  1171. /// ```
  1172. - #[stable(feature = "rust1", since = "1.0.0")]
  1173. pub fn limit(&self) -> u64 { self.limit }
  1174. /// Consumes the `Take`, returning the wrapped reader.
  1175. @@ -1536,13 +1496,11 @@ impl<T> Take<T> {
  1176. /// # Ok(())
  1177. /// # }
  1178. /// ```
  1179. - #[unstable(feature = "io_take_into_inner", issue = "23755")]
  1180. pub fn into_inner(self) -> T {
  1181. self.inner
  1182. }
  1183. }
  1184. -#[stable(feature = "rust1", since = "1.0.0")]
  1185. impl<T: Read> Read for Take<T> {
  1186. fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
  1187. // Don't call into inner reader at all at EOF because it may still block
  1188. @@ -1557,7 +1515,7 @@ impl<T: Read> Read for Take<T> {
  1189. }
  1190. }
  1191. -#[stable(feature = "rust1", since = "1.0.0")]
  1192. +#[cfg(feature="collections")]
  1193. impl<T: BufRead> BufRead for Take<T> {
  1194. fn fill_buf(&mut self) -> Result<&[u8]> {
  1195. // Don't call into inner reader at all at EOF because it may still block
  1196. @@ -1596,12 +1554,10 @@ fn read_one_byte(reader: &mut Read) -> Option<Result<u8>> {
  1197. /// Please see the documentation of [`bytes()`] for more details.
  1198. ///
  1199. /// [`bytes()`]: trait.Read.html#method.bytes
  1200. -#[stable(feature = "rust1", since = "1.0.0")]
  1201. pub struct Bytes<R> {
  1202. inner: R,
  1203. }
  1204. -#[stable(feature = "rust1", since = "1.0.0")]
  1205. impl<R: Read> Iterator for Bytes<R> {
  1206. type Item = Result<u8>;
  1207. @@ -1616,8 +1572,6 @@ impl<R: Read> Iterator for Bytes<R> {
  1208. /// Please see the documentation of `chars()` for more details.
  1209. ///
  1210. /// [chars]: trait.Read.html#method.chars
  1211. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1212. - issue = "27802")]
  1213. pub struct Chars<R> {
  1214. inner: R,
  1215. }
  1216. @@ -1625,8 +1579,6 @@ pub struct Chars<R> {
  1217. /// An enumeration of possible errors that can be generated from the `Chars`
  1218. /// adapter.
  1219. #[derive(Debug)]
  1220. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1221. - issue = "27802")]
  1222. pub enum CharsError {
  1223. /// Variant representing that the underlying stream was read successfully
  1224. /// but it did not contain valid utf8 data.
  1225. @@ -1636,8 +1588,6 @@ pub enum CharsError {
  1226. Other(Error),
  1227. }
  1228. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1229. - issue = "27802")]
  1230. impl<R: Read> Iterator for Chars<R> {
  1231. type Item = result::Result<char, CharsError>;
  1232. @@ -1669,25 +1619,6 @@ impl<R: Read> Iterator for Chars<R> {
  1233. }
  1234. }
  1235. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1236. - issue = "27802")]
  1237. -impl std_error::Error for CharsError {
  1238. - fn description(&self) -> &str {
  1239. - match *self {
  1240. - CharsError::NotUtf8 => "invalid utf8 encoding",
  1241. - CharsError::Other(ref e) => std_error::Error::description(e),
  1242. - }
  1243. - }
  1244. - fn cause(&self) -> Option<&std_error::Error> {
  1245. - match *self {
  1246. - CharsError::NotUtf8 => None,
  1247. - CharsError::Other(ref e) => e.cause(),
  1248. - }
  1249. - }
  1250. -}
  1251. -
  1252. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1253. - issue = "27802")]
  1254. impl fmt::Display for CharsError {
  1255. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  1256. match *self {
  1257. @@ -1706,13 +1637,13 @@ impl fmt::Display for CharsError {
  1258. /// `BufRead`. Please see the documentation of `split()` for more details.
  1259. ///
  1260. /// [split]: trait.BufRead.html#method.split
  1261. -#[stable(feature = "rust1", since = "1.0.0")]
  1262. +#[cfg(feature="collections")]
  1263. pub struct Split<B> {
  1264. buf: B,
  1265. delim: u8,
  1266. }
  1267. -#[stable(feature = "rust1", since = "1.0.0")]
  1268. +#[cfg(feature="collections")]
  1269. impl<B: BufRead> Iterator for Split<B> {
  1270. type Item = Result<Vec<u8>>;
  1271. @@ -1737,12 +1668,12 @@ impl<B: BufRead> Iterator for Split<B> {
  1272. /// `BufRead`. Please see the documentation of `lines()` for more details.
  1273. ///
  1274. /// [lines]: trait.BufRead.html#method.lines
  1275. -#[stable(feature = "rust1", since = "1.0.0")]
  1276. +#[cfg(feature="collections")]
  1277. pub struct Lines<B> {
  1278. buf: B,
  1279. }
  1280. -#[stable(feature = "rust1", since = "1.0.0")]
  1281. +#[cfg(feature="collections")]
  1282. impl<B: BufRead> Iterator for Lines<B> {
  1283. type Item = Result<String>;
  1284. diff --git a/prelude.rs b/prelude.rs
  1285. index 8772d0f..49d66c9 100644
  1286. --- a/prelude.rs
  1287. +++ b/prelude.rs
  1288. @@ -18,7 +18,8 @@
  1289. //! use std::io::prelude::*;
  1290. //! ```
  1291. -#![stable(feature = "rust1", since = "1.0.0")]
  1292. +pub use super::{Read, Write, Seek};
  1293. +#[cfg(feature="collections")] pub use super::BufRead;
  1294. -#[stable(feature = "rust1", since = "1.0.0")]
  1295. -pub use super::{Read, Write, BufRead, Seek};
  1296. +#[cfg(feature="collections")] pub use alloc::boxed::Box;
  1297. +#[cfg(feature="collections")] pub use collections::vec::Vec;
  1298. diff --git a/util.rs b/util.rs
  1299. index 2c68802..93bcfc3 100644
  1300. --- a/util.rs
  1301. +++ b/util.rs
  1302. @@ -10,7 +10,8 @@
  1303. #![allow(missing_copy_implementations)]
  1304. -use io::{self, Read, Write, ErrorKind, BufRead};
  1305. +use io::{self, Read, Write, ErrorKind};
  1306. +#[cfg(feature="collections")] use io::BufRead;
  1307. /// Copies the entire contents of a reader into a writer.
  1308. ///
  1309. @@ -42,7 +43,6 @@ use io::{self, Read, Write, ErrorKind, BufRead};
  1310. /// # Ok(())
  1311. /// # }
  1312. /// ```
  1313. -#[stable(feature = "rust1", since = "1.0.0")]
  1314. pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<u64>
  1315. where R: Read, W: Write
  1316. {
  1317. @@ -66,7 +66,6 @@ pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<
  1318. /// the documentation of `empty()` for more details.
  1319. ///
  1320. /// [empty]: fn.empty.html
  1321. -#[stable(feature = "rust1", since = "1.0.0")]
  1322. pub struct Empty { _priv: () }
  1323. /// Constructs a new handle to an empty reader.
  1324. @@ -84,14 +83,12 @@ pub struct Empty { _priv: () }
  1325. /// io::empty().read_to_string(&mut buffer).unwrap();
  1326. /// assert!(buffer.is_empty());
  1327. /// ```
  1328. -#[stable(feature = "rust1", since = "1.0.0")]
  1329. pub fn empty() -> Empty { Empty { _priv: () } }
  1330. -#[stable(feature = "rust1", since = "1.0.0")]
  1331. impl Read for Empty {
  1332. fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> { Ok(0) }
  1333. }
  1334. -#[stable(feature = "rust1", since = "1.0.0")]
  1335. +#[cfg(feature="collections")]
  1336. impl BufRead for Empty {
  1337. fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) }
  1338. fn consume(&mut self, _n: usize) {}
  1339. @@ -103,7 +100,6 @@ impl BufRead for Empty {
  1340. /// see the documentation of `repeat()` for more details.
  1341. ///
  1342. /// [repeat]: fn.repeat.html
  1343. -#[stable(feature = "rust1", since = "1.0.0")]
  1344. pub struct Repeat { byte: u8 }
  1345. /// Creates an instance of a reader that infinitely repeats one byte.
  1346. @@ -120,10 +116,8 @@ pub struct Repeat { byte: u8 }
  1347. /// io::repeat(0b101).read_exact(&mut buffer).unwrap();
  1348. /// assert_eq!(buffer, [0b101, 0b101, 0b101]);
  1349. /// ```
  1350. -#[stable(feature = "rust1", since = "1.0.0")]
  1351. pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } }
  1352. -#[stable(feature = "rust1", since = "1.0.0")]
  1353. impl Read for Repeat {
  1354. fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
  1355. for slot in &mut *buf {
  1356. @@ -139,7 +133,6 @@ impl Read for Repeat {
  1357. /// see the documentation of `sink()` for more details.
  1358. ///
  1359. /// [sink]: fn.sink.html
  1360. -#[stable(feature = "rust1", since = "1.0.0")]
  1361. pub struct Sink { _priv: () }
  1362. /// Creates an instance of a writer which will successfully consume all data.
  1363. @@ -156,10 +149,8 @@ pub struct Sink { _priv: () }
  1364. /// let num_bytes = io::sink().write(&buffer).unwrap();
  1365. /// assert_eq!(num_bytes, 5);
  1366. /// ```
  1367. -#[stable(feature = "rust1", since = "1.0.0")]
  1368. pub fn sink() -> Sink { Sink { _priv: () } }
  1369. -#[stable(feature = "rust1", since = "1.0.0")]
  1370. impl Write for Sink {
  1371. fn write(&mut self, buf: &[u8]) -> io::Result<usize> { Ok(buf.len()) }
  1372. fn flush(&mut self) -> io::Result<()> { Ok(()) }