3024c1434a667425d30e4b0785857381323712aa.patch 56 KB

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