0f02309e4b0ea05ee905205278fb6d131341c41f.patch 52 KB

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