b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d.patch 54 KB

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