88badb98c74f764f6e4baea3f6c9d3fd16013023.patch 51 KB

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