fda473f00fa07b9a8246b104396f9922e54bff16.patch 53 KB

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