f1e191c0b959111aef19f3aa06b7f1743419470c.patch 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626
  1. diff --git a/buffered.rs b/buffered.rs
  2. index ccebf36..17e6955 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. @@ -773,7 +732,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 420fede..d4242f7 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 = try!(Read::read(&mut try!(self.fill_buf()), buf));
  337. + let n = try!(Read::read(&mut try!(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. fn write(&mut self, data: &[u8]) -> io::Result<usize> {
  360. let pos = cmp::min(self.pos, self.inner.len() as u64);
  361. @@ -239,7 +233,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. @@ -267,8 +261,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. fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
  377. let pos = cmp::min(self.pos, self.inner.len() as u64);
  378. let amt = try!((&mut self.inner[(pos as usize)..]).write(buf));
  379. diff --git a/error.rs b/error.rs
  380. index e3f17c8..50e3658 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. @@ -57,20 +57,22 @@ pub type Result<T> = result::Result<T, Error>;
  413. /// `Error` can be created with crafted error messages and a particular value of
  414. /// `ErrorKind`.
  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. @@ -78,47 +80,34 @@ struct Custom {
  435. /// This list is intended to grow over time and it is not recommended to
  436. /// exhaustively match against it.
  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. @@ -128,10 +117,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. @@ -139,21 +126,15 @@ 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. #[allow(missing_docs)]
  508. - #[unstable(feature = "read_exact_old", reason = "recently added",
  509. - issue = "0")]
  510. - #[rustc_deprecated(since = "1.6.0", reason = "renamed to UnexpectedEof")]
  511. UnexpectedEOF,
  512. /// An error returned when an operation could not be completed because an
  513. @@ -162,14 +143,9 @@ pub enum ErrorKind {
  514. /// This typically means that an operation could only succeed if it read a
  515. /// particular number of bytes but only a smaller number of bytes could be
  516. /// read.
  517. - #[stable(feature = "read_exact", since = "1.6.0")]
  518. UnexpectedEof,
  519. /// Any I/O error not part of this list.
  520. - #[unstable(feature = "io_error_internals",
  521. - reason = "better expressed through extensible enums that this \
  522. - enum cannot be exhaustively matched against",
  523. - issue = "0")]
  524. #[doc(hidden)]
  525. __Nonexhaustive,
  526. }
  527. @@ -193,14 +169,13 @@ impl Error {
  528. /// // errors can also be created from other errors
  529. /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error);
  530. /// ```
  531. - #[stable(feature = "rust1", since = "1.0.0")]
  532. pub fn new<E>(kind: ErrorKind, error: E) -> Error
  533. - where E: Into<Box<error::Error+Send+Sync>>
  534. + where E: Into<String>
  535. {
  536. Self::_new(kind, error.into())
  537. }
  538. - fn _new(kind: ErrorKind, error: Box<error::Error+Send+Sync>) -> Error {
  539. + fn _new(kind: ErrorKind, error: String) -> Error {
  540. Error {
  541. repr: Repr::Custom(Box::new(Custom {
  542. kind: kind,
  543. @@ -209,18 +184,7 @@ impl Error {
  544. }
  545. }
  546. - /// Returns an error representing the last OS error which occurred.
  547. - ///
  548. - /// This function reads the value of `errno` for the target platform (e.g.
  549. - /// `GetLastError` on Windows) and will return a corresponding instance of
  550. - /// `Error` for the error code.
  551. - #[stable(feature = "rust1", since = "1.0.0")]
  552. - pub fn last_os_error() -> Error {
  553. - Error::from_raw_os_error(sys::os::errno() as i32)
  554. - }
  555. -
  556. /// Creates a new instance of an `Error` from a particular OS error code.
  557. - #[stable(feature = "rust1", since = "1.0.0")]
  558. pub fn from_raw_os_error(code: i32) -> Error {
  559. Error { repr: Repr::Os(code) }
  560. }
  561. @@ -230,7 +194,6 @@ impl Error {
  562. /// If this `Error` was constructed via `last_os_error` or
  563. /// `from_raw_os_error`, then this function will return `Some`, otherwise
  564. /// it will return `None`.
  565. - #[stable(feature = "rust1", since = "1.0.0")]
  566. pub fn raw_os_error(&self) -> Option<i32> {
  567. match self.repr {
  568. Repr::Os(i) => Some(i),
  569. @@ -242,11 +205,10 @@ impl Error {
  570. ///
  571. /// If this `Error` was constructed via `new` then this function will
  572. /// return `Some`, otherwise it will return `None`.
  573. - #[stable(feature = "io_error_inner", since = "1.3.0")]
  574. - pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> {
  575. + pub fn get_ref(&self) -> Option<&String> {
  576. match self.repr {
  577. Repr::Os(..) => None,
  578. - Repr::Custom(ref c) => Some(&*c.error),
  579. + Repr::Custom(ref c) => Some(&c.error),
  580. }
  581. }
  582. @@ -255,11 +217,10 @@ impl Error {
  583. ///
  584. /// If this `Error` was constructed via `new` then this function will
  585. /// return `Some`, otherwise it will return `None`.
  586. - #[stable(feature = "io_error_inner", since = "1.3.0")]
  587. - pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> {
  588. + pub fn get_mut(&mut self) -> Option<&mut String> {
  589. match self.repr {
  590. Repr::Os(..) => None,
  591. - Repr::Custom(ref mut c) => Some(&mut *c.error),
  592. + Repr::Custom(ref mut c) => Some(&mut c.error),
  593. }
  594. }
  595. @@ -267,8 +228,7 @@ impl Error {
  596. ///
  597. /// If this `Error` was constructed via `new` then this function will
  598. /// return `Some`, otherwise it will return `None`.
  599. - #[stable(feature = "io_error_inner", since = "1.3.0")]
  600. - pub fn into_inner(self) -> Option<Box<error::Error+Send+Sync>> {
  601. + pub fn into_inner(self) -> Option<String> {
  602. match self.repr {
  603. Repr::Os(..) => None,
  604. Repr::Custom(c) => Some(c.error)
  605. @@ -276,10 +236,9 @@ impl Error {
  606. }
  607. /// Returns the corresponding `ErrorKind` for this error.
  608. - #[stable(feature = "rust1", since = "1.0.0")]
  609. pub fn kind(&self) -> ErrorKind {
  610. match self.repr {
  611. - Repr::Os(code) => sys::decode_error_kind(code),
  612. + Repr::Os(_code) => ErrorKind::Other,
  613. Repr::Custom(ref c) => c.kind,
  614. }
  615. }
  616. @@ -289,65 +248,23 @@ impl fmt::Debug for Repr {
  617. fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
  618. match *self {
  619. Repr::Os(ref code) =>
  620. - fmt.debug_struct("Os").field("code", code)
  621. - .field("message", &sys::os::error_string(*code)).finish(),
  622. + fmt.debug_struct("Os").field("code", code).finish(),
  623. Repr::Custom(ref c) => fmt.debug_tuple("Custom").field(c).finish(),
  624. }
  625. }
  626. }
  627. -#[stable(feature = "rust1", since = "1.0.0")]
  628. impl fmt::Display for Error {
  629. fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
  630. match self.repr {
  631. Repr::Os(code) => {
  632. - let detail = sys::os::error_string(code);
  633. - write!(fmt, "{} (os error {})", detail, code)
  634. + write!(fmt, "os error {}", code)
  635. }
  636. Repr::Custom(ref c) => c.error.fmt(fmt),
  637. }
  638. }
  639. }
  640. -#[stable(feature = "rust1", since = "1.0.0")]
  641. -impl error::Error for Error {
  642. - #[allow(deprecated)] // remove with UnexpectedEOF
  643. - fn description(&self) -> &str {
  644. - match self.repr {
  645. - Repr::Os(..) => match self.kind() {
  646. - ErrorKind::NotFound => "entity not found",
  647. - ErrorKind::PermissionDenied => "permission denied",
  648. - ErrorKind::ConnectionRefused => "connection refused",
  649. - ErrorKind::ConnectionReset => "connection reset",
  650. - ErrorKind::ConnectionAborted => "connection aborted",
  651. - ErrorKind::NotConnected => "not connected",
  652. - ErrorKind::AddrInUse => "address in use",
  653. - ErrorKind::AddrNotAvailable => "address not available",
  654. - ErrorKind::BrokenPipe => "broken pipe",
  655. - ErrorKind::AlreadyExists => "entity already exists",
  656. - ErrorKind::WouldBlock => "operation would block",
  657. - ErrorKind::InvalidInput => "invalid input parameter",
  658. - ErrorKind::InvalidData => "invalid data",
  659. - ErrorKind::TimedOut => "timed out",
  660. - ErrorKind::WriteZero => "write zero",
  661. - ErrorKind::Interrupted => "operation interrupted",
  662. - ErrorKind::Other => "other os error",
  663. - ErrorKind::UnexpectedEOF => "unexpected end of file",
  664. - ErrorKind::UnexpectedEof => "unexpected end of file",
  665. - ErrorKind::__Nonexhaustive => unreachable!()
  666. - },
  667. - Repr::Custom(ref c) => c.error.description(),
  668. - }
  669. - }
  670. -
  671. - fn cause(&self) -> Option<&error::Error> {
  672. - match self.repr {
  673. - Repr::Os(..) => None,
  674. - Repr::Custom(ref c) => c.error.cause(),
  675. - }
  676. - }
  677. -}
  678. -
  679. fn _assert_error_is_sync_send() {
  680. fn _is_sync_send<T: Sync+Send>() {}
  681. _is_sync_send::<Error>();
  682. diff --git a/impls.rs b/impls.rs
  683. index ec63f14..ac172bf 100644
  684. --- a/impls.rs
  685. +++ b/impls.rs
  686. @@ -8,29 +8,31 @@
  687. // option. This file may not be copied, modified, or distributed
  688. // except according to those terms.
  689. -use boxed::Box;
  690. -use cmp;
  691. -use io::{self, SeekFrom, Read, Write, Seek, BufRead, Error, ErrorKind};
  692. -use fmt;
  693. -use mem;
  694. -use string::String;
  695. -use vec::Vec;
  696. +#[cfg(feature="alloc")] use alloc::boxed::Box;
  697. +use core::cmp;
  698. +use io::{self, SeekFrom, Read, Write, Seek, Error, ErrorKind};
  699. +#[cfg(feature="collections")] use io::BufRead;
  700. +use core::fmt;
  701. +use core::mem;
  702. +#[cfg(feature="collections")] use collections::string::String;
  703. +#[cfg(feature="collections")] use collections::vec::Vec;
  704. // =============================================================================
  705. // Forwarding implementations
  706. -#[stable(feature = "rust1", since = "1.0.0")]
  707. impl<'a, R: Read + ?Sized> Read for &'a mut R {
  708. #[inline]
  709. fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
  710. (**self).read(buf)
  711. }
  712. + #[cfg(feature="collections")]
  713. #[inline]
  714. fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
  715. (**self).read_to_end(buf)
  716. }
  717. + #[cfg(feature="collections")]
  718. #[inline]
  719. fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
  720. (**self).read_to_string(buf)
  721. @@ -41,7 +43,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R {
  722. (**self).read_exact(buf)
  723. }
  724. }
  725. -#[stable(feature = "rust1", since = "1.0.0")]
  726. impl<'a, W: Write + ?Sized> Write for &'a mut W {
  727. #[inline]
  728. fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (**self).write(buf) }
  729. @@ -59,12 +60,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W {
  730. (**self).write_fmt(fmt)
  731. }
  732. }
  733. -#[stable(feature = "rust1", since = "1.0.0")]
  734. impl<'a, S: Seek + ?Sized> Seek for &'a mut S {
  735. #[inline]
  736. fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { (**self).seek(pos) }
  737. }
  738. -#[stable(feature = "rust1", since = "1.0.0")]
  739. +#[cfg(feature="collections")]
  740. impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B {
  741. #[inline]
  742. fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() }
  743. @@ -83,18 +83,20 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B {
  744. }
  745. }
  746. -#[stable(feature = "rust1", since = "1.0.0")]
  747. +#[cfg(feature="alloc")]
  748. impl<R: Read + ?Sized> Read for Box<R> {
  749. #[inline]
  750. fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
  751. (**self).read(buf)
  752. }
  753. + #[cfg(feature="collections")]
  754. #[inline]
  755. fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
  756. (**self).read_to_end(buf)
  757. }
  758. + #[cfg(feature="collections")]
  759. #[inline]
  760. fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
  761. (**self).read_to_string(buf)
  762. @@ -105,7 +107,7 @@ impl<R: Read + ?Sized> Read for Box<R> {
  763. (**self).read_exact(buf)
  764. }
  765. }
  766. -#[stable(feature = "rust1", since = "1.0.0")]
  767. +#[cfg(feature="alloc")]
  768. impl<W: Write + ?Sized> Write for Box<W> {
  769. #[inline]
  770. fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (**self).write(buf) }
  771. @@ -123,12 +125,12 @@ impl<W: Write + ?Sized> Write for Box<W> {
  772. (**self).write_fmt(fmt)
  773. }
  774. }
  775. -#[stable(feature = "rust1", since = "1.0.0")]
  776. +#[cfg(feature="alloc")]
  777. impl<S: Seek + ?Sized> Seek for Box<S> {
  778. #[inline]
  779. fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { (**self).seek(pos) }
  780. }
  781. -#[stable(feature = "rust1", since = "1.0.0")]
  782. +#[cfg(feature="collections")]
  783. impl<B: BufRead + ?Sized> BufRead for Box<B> {
  784. #[inline]
  785. fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() }
  786. @@ -150,7 +152,6 @@ impl<B: BufRead + ?Sized> BufRead for Box<B> {
  787. // =============================================================================
  788. // In-memory buffer implementations
  789. -#[stable(feature = "rust1", since = "1.0.0")]
  790. impl<'a> Read for &'a [u8] {
  791. #[inline]
  792. fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
  793. @@ -174,7 +175,7 @@ impl<'a> Read for &'a [u8] {
  794. }
  795. }
  796. -#[stable(feature = "rust1", since = "1.0.0")]
  797. +#[cfg(feature="collections")]
  798. impl<'a> BufRead for &'a [u8] {
  799. #[inline]
  800. fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) }
  801. @@ -183,7 +184,6 @@ impl<'a> BufRead for &'a [u8] {
  802. fn consume(&mut self, amt: usize) { *self = &self[amt..]; }
  803. }
  804. -#[stable(feature = "rust1", since = "1.0.0")]
  805. impl<'a> Write for &'a mut [u8] {
  806. #[inline]
  807. fn write(&mut self, data: &[u8]) -> io::Result<usize> {
  808. @@ -207,7 +207,7 @@ impl<'a> Write for &'a mut [u8] {
  809. fn flush(&mut self) -> io::Result<()> { Ok(()) }
  810. }
  811. -#[stable(feature = "rust1", since = "1.0.0")]
  812. +#[cfg(feature="collections")]
  813. impl Write for Vec<u8> {
  814. #[inline]
  815. fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
  816. diff --git a/memchr.rs b/memchr.rs
  817. index 1d97611..110cfac 100644
  818. --- a/memchr.rs
  819. +++ b/memchr.rs
  820. @@ -11,103 +11,12 @@
  821. // Original implementation taken from rust-memchr
  822. // Copyright 2015 Andrew Gallant, bluss and Nicolas Koch
  823. -
  824. -
  825. -/// A safe interface to `memchr`.
  826. -///
  827. -/// Returns the index corresponding to the first occurrence of `needle` in
  828. -/// `haystack`, or `None` if one is not found.
  829. -///
  830. -/// memchr reduces to super-optimized machine code at around an order of
  831. -/// magnitude faster than `haystack.iter().position(|&b| b == needle)`.
  832. -/// (See benchmarks.)
  833. -///
  834. -/// # Example
  835. -///
  836. -/// This shows how to find the first position of a byte in a byte string.
  837. -///
  838. -/// ```rust,ignore
  839. -/// use memchr::memchr;
  840. -///
  841. -/// let haystack = b"the quick brown fox";
  842. -/// assert_eq!(memchr(b'k', haystack), Some(8));
  843. -/// ```
  844. -pub fn memchr(needle: u8, haystack: &[u8]) -> Option<usize> {
  845. - // libc memchr
  846. - #[cfg(not(target_os = "windows"))]
  847. - fn memchr_specific(needle: u8, haystack: &[u8]) -> Option<usize> {
  848. - use libc;
  849. -
  850. - let p = unsafe {
  851. - libc::memchr(
  852. - haystack.as_ptr() as *const libc::c_void,
  853. - needle as libc::c_int,
  854. - haystack.len() as libc::size_t)
  855. - };
  856. - if p.is_null() {
  857. - None
  858. - } else {
  859. - Some(p as usize - (haystack.as_ptr() as usize))
  860. - }
  861. - }
  862. -
  863. - // use fallback on windows, since it's faster
  864. - #[cfg(target_os = "windows")]
  865. - fn memchr_specific(needle: u8, haystack: &[u8]) -> Option<usize> {
  866. - fallback::memchr(needle, haystack)
  867. - }
  868. -
  869. - memchr_specific(needle, haystack)
  870. -}
  871. -
  872. -/// A safe interface to `memrchr`.
  873. -///
  874. -/// Returns the index corresponding to the last occurrence of `needle` in
  875. -/// `haystack`, or `None` if one is not found.
  876. -///
  877. -/// # Example
  878. -///
  879. -/// This shows how to find the last position of a byte in a byte string.
  880. -///
  881. -/// ```rust,ignore
  882. -/// use memchr::memrchr;
  883. -///
  884. -/// let haystack = b"the quick brown fox";
  885. -/// assert_eq!(memrchr(b'o', haystack), Some(17));
  886. -/// ```
  887. -pub fn memrchr(needle: u8, haystack: &[u8]) -> Option<usize> {
  888. -
  889. - #[cfg(target_os = "linux")]
  890. - fn memrchr_specific(needle: u8, haystack: &[u8]) -> Option<usize> {
  891. - use libc;
  892. -
  893. - // GNU's memrchr() will - unlike memchr() - error if haystack is empty.
  894. - if haystack.is_empty() {return None}
  895. - let p = unsafe {
  896. - libc::memrchr(
  897. - haystack.as_ptr() as *const libc::c_void,
  898. - needle as libc::c_int,
  899. - haystack.len() as libc::size_t)
  900. - };
  901. - if p.is_null() {
  902. - None
  903. - } else {
  904. - Some(p as usize - (haystack.as_ptr() as usize))
  905. - }
  906. - }
  907. -
  908. - #[cfg(not(target_os = "linux"))]
  909. - fn memrchr_specific(needle: u8, haystack: &[u8]) -> Option<usize> {
  910. - fallback::memrchr(needle, haystack)
  911. - }
  912. -
  913. - memrchr_specific(needle, haystack)
  914. -}
  915. +pub use self::fallback::{memchr,memrchr};
  916. #[allow(dead_code)]
  917. mod fallback {
  918. - use cmp;
  919. - use mem;
  920. + use core::cmp;
  921. + use core::mem;
  922. const LO_U64: u64 = 0x0101010101010101;
  923. const HI_U64: u64 = 0x8080808080808080;
  924. diff --git a/mod.rs b/mod.rs
  925. index 61334f3..26b9102 100644
  926. --- a/mod.rs
  927. +++ b/mod.rs
  928. @@ -248,49 +248,32 @@
  929. //! contract. The implementation of many of these functions are subject to change over
  930. //! time and may call fewer or more syscalls/library functions.
  931. -#![stable(feature = "rust1", since = "1.0.0")]
  932. -
  933. -use cmp;
  934. +use core::cmp;
  935. use rustc_unicode::str as core_str;
  936. -use error as std_error;
  937. -use fmt;
  938. -use iter::{Iterator};
  939. -use marker::Sized;
  940. -use ops::{Drop, FnOnce};
  941. -use option::Option::{self, Some, None};
  942. -use result::Result::{Ok, Err};
  943. -use result;
  944. -use string::String;
  945. -use str;
  946. -use vec::Vec;
  947. -use memchr;
  948. -
  949. -#[stable(feature = "rust1", since = "1.0.0")]
  950. -pub use self::buffered::{BufReader, BufWriter, LineWriter};
  951. -#[stable(feature = "rust1", since = "1.0.0")]
  952. -pub use self::buffered::IntoInnerError;
  953. -#[stable(feature = "rust1", since = "1.0.0")]
  954. +use core::fmt;
  955. +use core::iter::{Iterator};
  956. +use core::marker::Sized;
  957. +#[cfg(feature="collections")] use core::ops::{Drop, FnOnce};
  958. +use core::option::Option::{self, Some, None};
  959. +use core::result::Result::{Ok, Err};
  960. +use core::result;
  961. +#[cfg(feature="collections")] use collections::string::String;
  962. +use core::str;
  963. +#[cfg(feature="collections")] use collections::vec::Vec;
  964. +mod memchr;
  965. +
  966. +#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter};
  967. +#[cfg(feature="collections")] pub use self::buffered::IntoInnerError;
  968. pub use self::cursor::Cursor;
  969. -#[stable(feature = "rust1", since = "1.0.0")]
  970. pub use self::error::{Result, Error, ErrorKind};
  971. -#[stable(feature = "rust1", since = "1.0.0")]
  972. pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat};
  973. -#[stable(feature = "rust1", since = "1.0.0")]
  974. -pub use self::stdio::{stdin, stdout, stderr, _print, Stdin, Stdout, Stderr};
  975. -#[stable(feature = "rust1", since = "1.0.0")]
  976. -pub use self::stdio::{StdoutLock, StderrLock, StdinLock};
  977. -#[unstable(feature = "libstd_io_internals", issue = "0")]
  978. -#[doc(no_inline, hidden)]
  979. -pub use self::stdio::{set_panic, set_print};
  980. pub mod prelude;
  981. -mod buffered;
  982. +#[cfg(feature="collections")] mod buffered;
  983. mod cursor;
  984. mod error;
  985. mod impls;
  986. -mod lazy;
  987. mod util;
  988. -mod stdio;
  989. const DEFAULT_BUF_SIZE: usize = 64 * 1024;
  990. @@ -312,6 +295,7 @@ const DEFAULT_BUF_SIZE: usize = 64 * 1024;
  991. // 2. We're passing a raw buffer to the function `f`, and it is expected that
  992. // the function only *appends* bytes to the buffer. We'll get undefined
  993. // behavior if existing bytes are overwritten to have non-UTF-8 data.
  994. +#[cfg(feature="collections")]
  995. fn append_to_string<F>(buf: &mut String, f: F) -> Result<usize>
  996. where F: FnOnce(&mut Vec<u8>) -> Result<usize>
  997. {
  998. @@ -343,6 +327,7 @@ fn append_to_string<F>(buf: &mut String, f: F) -> Result<usize>
  999. // of data to return. Simply tacking on an extra DEFAULT_BUF_SIZE space every
  1000. // time is 4,500 times (!) slower than this if the reader has a very small
  1001. // amount of data to return.
  1002. +#[cfg(feature="collections")]
  1003. fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize> {
  1004. let start_len = buf.len();
  1005. let mut len = start_len;
  1006. @@ -425,7 +410,6 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
  1007. /// # Ok(())
  1008. /// # }
  1009. /// ```
  1010. -#[stable(feature = "rust1", since = "1.0.0")]
  1011. pub trait Read {
  1012. /// Pull some bytes from this source into the specified buffer, returning
  1013. /// how many bytes were read.
  1014. @@ -475,7 +459,6 @@ pub trait Read {
  1015. /// # Ok(())
  1016. /// # }
  1017. /// ```
  1018. - #[stable(feature = "rust1", since = "1.0.0")]
  1019. fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
  1020. /// Read all bytes until EOF in this source, placing them into `buf`.
  1021. @@ -517,7 +500,7 @@ pub trait Read {
  1022. /// # Ok(())
  1023. /// # }
  1024. /// ```
  1025. - #[stable(feature = "rust1", since = "1.0.0")]
  1026. + #[cfg(feature="collections")]
  1027. fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> {
  1028. read_to_end(self, buf)
  1029. }
  1030. @@ -555,7 +538,7 @@ pub trait Read {
  1031. /// # Ok(())
  1032. /// # }
  1033. /// ```
  1034. - #[stable(feature = "rust1", since = "1.0.0")]
  1035. + #[cfg(feature="collections")]
  1036. fn read_to_string(&mut self, buf: &mut String) -> Result<usize> {
  1037. // Note that we do *not* call `.read_to_end()` here. We are passing
  1038. // `&mut Vec<u8>` (the raw contents of `buf`) into the `read_to_end`
  1039. @@ -616,7 +599,6 @@ pub trait Read {
  1040. /// # Ok(())
  1041. /// # }
  1042. /// ```
  1043. - #[stable(feature = "read_exact", since = "1.6.0")]
  1044. fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> {
  1045. while !buf.is_empty() {
  1046. match self.read(buf) {
  1047. @@ -668,7 +650,6 @@ pub trait Read {
  1048. /// # Ok(())
  1049. /// # }
  1050. /// ```
  1051. - #[stable(feature = "rust1", since = "1.0.0")]
  1052. fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
  1053. /// Transforms this `Read` instance to an `Iterator` over its bytes.
  1054. @@ -698,7 +679,6 @@ pub trait Read {
  1055. /// # Ok(())
  1056. /// # }
  1057. /// ```
  1058. - #[stable(feature = "rust1", since = "1.0.0")]
  1059. fn bytes(self) -> Bytes<Self> where Self: Sized {
  1060. Bytes { inner: self }
  1061. }
  1062. @@ -735,10 +715,6 @@ pub trait Read {
  1063. /// # Ok(())
  1064. /// # }
  1065. /// ```
  1066. - #[unstable(feature = "io", reason = "the semantics of a partial read/write \
  1067. - of where errors happen is currently \
  1068. - unclear and may change",
  1069. - issue = "27802")]
  1070. fn chars(self) -> Chars<Self> where Self: Sized {
  1071. Chars { inner: self }
  1072. }
  1073. @@ -773,7 +749,6 @@ pub trait Read {
  1074. /// # Ok(())
  1075. /// # }
  1076. /// ```
  1077. - #[stable(feature = "rust1", since = "1.0.0")]
  1078. fn chain<R: Read>(self, next: R) -> Chain<Self, R> where Self: Sized {
  1079. Chain { first: self, second: next, done_first: false }
  1080. }
  1081. @@ -807,7 +782,6 @@ pub trait Read {
  1082. /// # Ok(())
  1083. /// # }
  1084. /// ```
  1085. - #[stable(feature = "rust1", since = "1.0.0")]
  1086. fn take(self, limit: u64) -> Take<Self> where Self: Sized {
  1087. Take { inner: self, limit: limit }
  1088. }
  1089. @@ -843,13 +817,6 @@ pub trait Read {
  1090. /// # Ok(())
  1091. /// # }
  1092. /// ```
  1093. - #[unstable(feature = "io", reason = "the semantics of a partial read/write \
  1094. - of where errors happen is currently \
  1095. - unclear and may change",
  1096. - issue = "27802")]
  1097. - #[rustc_deprecated(reason = "error handling semantics unclear and \
  1098. - don't seem to have an ergonomic resolution",
  1099. - since = "1.6.0")]
  1100. #[allow(deprecated)]
  1101. fn tee<W: Write>(self, out: W) -> Tee<Self, W> where Self: Sized {
  1102. Tee { reader: self, writer: out }
  1103. @@ -886,7 +853,6 @@ pub trait Read {
  1104. /// # Ok(())
  1105. /// # }
  1106. /// ```
  1107. -#[stable(feature = "rust1", since = "1.0.0")]
  1108. pub trait Write {
  1109. /// Write a buffer into this object, returning how many bytes were written.
  1110. ///
  1111. @@ -926,7 +892,6 @@ pub trait Write {
  1112. /// # Ok(())
  1113. /// # }
  1114. /// ```
  1115. - #[stable(feature = "rust1", since = "1.0.0")]
  1116. fn write(&mut self, buf: &[u8]) -> Result<usize>;
  1117. /// Flush this output stream, ensuring that all intermediately buffered
  1118. @@ -952,7 +917,6 @@ pub trait Write {
  1119. /// # Ok(())
  1120. /// # }
  1121. /// ```
  1122. - #[stable(feature = "rust1", since = "1.0.0")]
  1123. fn flush(&mut self) -> Result<()>;
  1124. /// Attempts to write an entire buffer into this write.
  1125. @@ -979,7 +943,6 @@ pub trait Write {
  1126. /// # Ok(())
  1127. /// # }
  1128. /// ```
  1129. - #[stable(feature = "rust1", since = "1.0.0")]
  1130. fn write_all(&mut self, mut buf: &[u8]) -> Result<()> {
  1131. while !buf.is_empty() {
  1132. match self.write(buf) {
  1133. @@ -1031,7 +994,6 @@ pub trait Write {
  1134. /// # Ok(())
  1135. /// # }
  1136. /// ```
  1137. - #[stable(feature = "rust1", since = "1.0.0")]
  1138. fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> {
  1139. // Create a shim which translates a Write to a fmt::Write and saves
  1140. // off I/O errors. instead of discarding them
  1141. @@ -1087,7 +1049,6 @@ pub trait Write {
  1142. /// # Ok(())
  1143. /// # }
  1144. /// ```
  1145. - #[stable(feature = "rust1", since = "1.0.0")]
  1146. fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
  1147. /// Creates a new writer which will write all data to both this writer and
  1148. @@ -1117,13 +1078,6 @@ pub trait Write {
  1149. /// # Ok(())
  1150. /// # }
  1151. /// ```
  1152. - #[unstable(feature = "io", reason = "the semantics of a partial read/write \
  1153. - of where errors happen is currently \
  1154. - unclear and may change",
  1155. - issue = "27802")]
  1156. - #[rustc_deprecated(reason = "error handling semantics unclear and \
  1157. - don't seem to have an ergonomic resolution",
  1158. - since = "1.6.0")]
  1159. #[allow(deprecated)]
  1160. fn broadcast<W: Write>(self, other: W) -> Broadcast<Self, W>
  1161. where Self: Sized
  1162. @@ -1158,7 +1112,6 @@ pub trait Write {
  1163. /// # Ok(())
  1164. /// # }
  1165. /// ```
  1166. -#[stable(feature = "rust1", since = "1.0.0")]
  1167. pub trait Seek {
  1168. /// Seek to an offset, in bytes, in a stream.
  1169. ///
  1170. @@ -1172,35 +1125,31 @@ pub trait Seek {
  1171. /// # Errors
  1172. ///
  1173. /// Seeking to a negative offset is considered an error.
  1174. - #[stable(feature = "rust1", since = "1.0.0")]
  1175. fn seek(&mut self, pos: SeekFrom) -> Result<u64>;
  1176. }
  1177. /// Enumeration of possible methods to seek within an I/O object.
  1178. #[derive(Copy, PartialEq, Eq, Clone, Debug)]
  1179. -#[stable(feature = "rust1", since = "1.0.0")]
  1180. pub enum SeekFrom {
  1181. /// Set the offset to the provided number of bytes.
  1182. - #[stable(feature = "rust1", since = "1.0.0")]
  1183. - Start(#[stable(feature = "rust1", since = "1.0.0")] u64),
  1184. + Start(u64),
  1185. /// Set the offset to the size of this object plus the specified number of
  1186. /// bytes.
  1187. ///
  1188. /// It is possible to seek beyond the end of an object, but it's an error to
  1189. /// seek before byte 0.
  1190. - #[stable(feature = "rust1", since = "1.0.0")]
  1191. - End(#[stable(feature = "rust1", since = "1.0.0")] i64),
  1192. + End(i64),
  1193. /// Set the offset to the current position plus the specified number of
  1194. /// bytes.
  1195. ///
  1196. /// It is possible to seek beyond the end of an object, but it's an error to
  1197. /// seek before byte 0.
  1198. - #[stable(feature = "rust1", since = "1.0.0")]
  1199. - Current(#[stable(feature = "rust1", since = "1.0.0")] i64),
  1200. + Current(i64),
  1201. }
  1202. +#[cfg(feature="collections")]
  1203. fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
  1204. -> Result<usize> {
  1205. let mut read = 0;
  1206. @@ -1280,7 +1229,7 @@ fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
  1207. /// # }
  1208. /// ```
  1209. ///
  1210. -#[stable(feature = "rust1", since = "1.0.0")]
  1211. +#[cfg(feature="collections")]
  1212. pub trait BufRead: Read {
  1213. /// Fills the internal buffer of this object, returning the buffer contents.
  1214. ///
  1215. @@ -1325,7 +1274,6 @@ pub trait BufRead: Read {
  1216. /// // ensure the bytes we worked with aren't returned again later
  1217. /// stdin.consume(length);
  1218. /// ```
  1219. - #[stable(feature = "rust1", since = "1.0.0")]
  1220. fn fill_buf(&mut self) -> Result<&[u8]>;
  1221. /// Tells this buffer that `amt` bytes have been consumed from the buffer,
  1222. @@ -1347,7 +1295,6 @@ pub trait BufRead: Read {
  1223. ///
  1224. /// Since `consume()` is meant to be used with [`fill_buf()`][fillbuf],
  1225. /// that method's example includes an example of `consume()`.
  1226. - #[stable(feature = "rust1", since = "1.0.0")]
  1227. fn consume(&mut self, amt: usize);
  1228. /// Read all bytes into `buf` until the delimiter `byte` is reached.
  1229. @@ -1388,7 +1335,6 @@ pub trait BufRead: Read {
  1230. /// # Ok(())
  1231. /// # }
  1232. /// ```
  1233. - #[stable(feature = "rust1", since = "1.0.0")]
  1234. fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize> {
  1235. read_until(self, byte, buf)
  1236. }
  1237. @@ -1436,7 +1382,6 @@ pub trait BufRead: Read {
  1238. /// buffer.clear();
  1239. /// }
  1240. /// ```
  1241. - #[stable(feature = "rust1", since = "1.0.0")]
  1242. fn read_line(&mut self, buf: &mut String) -> Result<usize> {
  1243. // Note that we are not calling the `.read_until` method here, but
  1244. // rather our hardcoded implementation. For more details as to why, see
  1245. @@ -1469,7 +1414,6 @@ pub trait BufRead: Read {
  1246. /// println!("{:?}", content.unwrap());
  1247. /// }
  1248. /// ```
  1249. - #[stable(feature = "rust1", since = "1.0.0")]
  1250. fn split(self, byte: u8) -> Split<Self> where Self: Sized {
  1251. Split { buf: self, delim: byte }
  1252. }
  1253. @@ -1494,7 +1438,6 @@ pub trait BufRead: Read {
  1254. /// println!("{}", line.unwrap());
  1255. /// }
  1256. /// ```
  1257. - #[stable(feature = "rust1", since = "1.0.0")]
  1258. fn lines(self) -> Lines<Self> where Self: Sized {
  1259. Lines { buf: self }
  1260. }
  1261. @@ -1506,21 +1449,11 @@ pub trait BufRead: Read {
  1262. /// writer. Please see the documentation of `broadcast()` for more details.
  1263. ///
  1264. /// [broadcast]: trait.Write.html#method.broadcast
  1265. -#[unstable(feature = "io", reason = "awaiting stability of Write::broadcast",
  1266. - issue = "27802")]
  1267. -#[rustc_deprecated(reason = "error handling semantics unclear and \
  1268. - don't seem to have an ergonomic resolution",
  1269. - since = "1.6.0")]
  1270. pub struct Broadcast<T, U> {
  1271. first: T,
  1272. second: U,
  1273. }
  1274. -#[unstable(feature = "io", reason = "awaiting stability of Write::broadcast",
  1275. - issue = "27802")]
  1276. -#[rustc_deprecated(reason = "error handling semantics unclear and \
  1277. - don't seem to have an ergonomic resolution",
  1278. - since = "1.6.0")]
  1279. #[allow(deprecated)]
  1280. impl<T: Write, U: Write> Write for Broadcast<T, U> {
  1281. fn write(&mut self, data: &[u8]) -> Result<usize> {
  1282. @@ -1541,14 +1474,12 @@ impl<T: Write, U: Write> Write for Broadcast<T, U> {
  1283. /// Please see the documentation of `chain()` for more details.
  1284. ///
  1285. /// [chain]: trait.Read.html#method.chain
  1286. -#[stable(feature = "rust1", since = "1.0.0")]
  1287. pub struct Chain<T, U> {
  1288. first: T,
  1289. second: U,
  1290. done_first: bool,
  1291. }
  1292. -#[stable(feature = "rust1", since = "1.0.0")]
  1293. impl<T: Read, U: Read> Read for Chain<T, U> {
  1294. fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
  1295. if !self.done_first {
  1296. @@ -1567,7 +1498,6 @@ impl<T: Read, U: Read> Read for Chain<T, U> {
  1297. /// Please see the documentation of `take()` for more details.
  1298. ///
  1299. /// [take]: trait.Read.html#method.take
  1300. -#[stable(feature = "rust1", since = "1.0.0")]
  1301. pub struct Take<T> {
  1302. inner: T,
  1303. limit: u64,
  1304. @@ -1581,11 +1511,9 @@ impl<T> Take<T> {
  1305. ///
  1306. /// This instance may reach EOF after reading fewer bytes than indicated by
  1307. /// this method if the underlying `Read` instance reaches EOF.
  1308. - #[stable(feature = "rust1", since = "1.0.0")]
  1309. pub fn limit(&self) -> u64 { self.limit }
  1310. }
  1311. -#[stable(feature = "rust1", since = "1.0.0")]
  1312. impl<T: Read> Read for Take<T> {
  1313. fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
  1314. // Don't call into inner reader at all at EOF because it may still block
  1315. @@ -1600,7 +1528,7 @@ impl<T: Read> Read for Take<T> {
  1316. }
  1317. }
  1318. -#[stable(feature = "rust1", since = "1.0.0")]
  1319. +#[cfg(feature="collections")]
  1320. impl<T: BufRead> BufRead for Take<T> {
  1321. fn fill_buf(&mut self) -> Result<&[u8]> {
  1322. let buf = try!(self.inner.fill_buf());
  1323. @@ -1622,21 +1550,11 @@ impl<T: BufRead> BufRead for Take<T> {
  1324. /// Please see the documentation of `tee()` for more details.
  1325. ///
  1326. /// [tee]: trait.Read.html#method.tee
  1327. -#[unstable(feature = "io", reason = "awaiting stability of Read::tee",
  1328. - issue = "27802")]
  1329. -#[rustc_deprecated(reason = "error handling semantics unclear and \
  1330. - don't seem to have an ergonomic resolution",
  1331. - since = "1.6.0")]
  1332. pub struct Tee<R, W> {
  1333. reader: R,
  1334. writer: W,
  1335. }
  1336. -#[unstable(feature = "io", reason = "awaiting stability of Read::tee",
  1337. - issue = "27802")]
  1338. -#[rustc_deprecated(reason = "error handling semantics unclear and \
  1339. - don't seem to have an ergonomic resolution",
  1340. - since = "1.6.0")]
  1341. #[allow(deprecated)]
  1342. impl<R: Read, W: Write> Read for Tee<R, W> {
  1343. fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
  1344. @@ -1653,12 +1571,10 @@ impl<R: Read, W: Write> Read for Tee<R, W> {
  1345. /// Please see the documentation of `bytes()` for more details.
  1346. ///
  1347. /// [bytes]: trait.Read.html#method.bytes
  1348. -#[stable(feature = "rust1", since = "1.0.0")]
  1349. pub struct Bytes<R> {
  1350. inner: R,
  1351. }
  1352. -#[stable(feature = "rust1", since = "1.0.0")]
  1353. impl<R: Read> Iterator for Bytes<R> {
  1354. type Item = Result<u8>;
  1355. @@ -1678,8 +1594,6 @@ impl<R: Read> Iterator for Bytes<R> {
  1356. /// Please see the documentation of `chars()` for more details.
  1357. ///
  1358. /// [chars]: trait.Read.html#method.chars
  1359. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1360. - issue = "27802")]
  1361. pub struct Chars<R> {
  1362. inner: R,
  1363. }
  1364. @@ -1687,8 +1601,6 @@ pub struct Chars<R> {
  1365. /// An enumeration of possible errors that can be generated from the `Chars`
  1366. /// adapter.
  1367. #[derive(Debug)]
  1368. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1369. - issue = "27802")]
  1370. pub enum CharsError {
  1371. /// Variant representing that the underlying stream was read successfully
  1372. /// but it did not contain valid utf8 data.
  1373. @@ -1698,8 +1610,6 @@ pub enum CharsError {
  1374. Other(Error),
  1375. }
  1376. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1377. - issue = "27802")]
  1378. impl<R: Read> Iterator for Chars<R> {
  1379. type Item = result::Result<char, CharsError>;
  1380. @@ -1731,25 +1641,6 @@ impl<R: Read> Iterator for Chars<R> {
  1381. }
  1382. }
  1383. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1384. - issue = "27802")]
  1385. -impl std_error::Error for CharsError {
  1386. - fn description(&self) -> &str {
  1387. - match *self {
  1388. - CharsError::NotUtf8 => "invalid utf8 encoding",
  1389. - CharsError::Other(ref e) => std_error::Error::description(e),
  1390. - }
  1391. - }
  1392. - fn cause(&self) -> Option<&std_error::Error> {
  1393. - match *self {
  1394. - CharsError::NotUtf8 => None,
  1395. - CharsError::Other(ref e) => e.cause(),
  1396. - }
  1397. - }
  1398. -}
  1399. -
  1400. -#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
  1401. - issue = "27802")]
  1402. impl fmt::Display for CharsError {
  1403. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  1404. match *self {
  1405. @@ -1768,13 +1659,13 @@ impl fmt::Display for CharsError {
  1406. /// `BufRead`. Please see the documentation of `split()` for more details.
  1407. ///
  1408. /// [split]: trait.BufRead.html#method.split
  1409. -#[stable(feature = "rust1", since = "1.0.0")]
  1410. +#[cfg(feature="collections")]
  1411. pub struct Split<B> {
  1412. buf: B,
  1413. delim: u8,
  1414. }
  1415. -#[stable(feature = "rust1", since = "1.0.0")]
  1416. +#[cfg(feature="collections")]
  1417. impl<B: BufRead> Iterator for Split<B> {
  1418. type Item = Result<Vec<u8>>;
  1419. @@ -1799,12 +1690,12 @@ impl<B: BufRead> Iterator for Split<B> {
  1420. /// `BufRead`. Please see the documentation of `lines()` for more details.
  1421. ///
  1422. /// [lines]: trait.BufRead.html#method.lines
  1423. -#[stable(feature = "rust1", since = "1.0.0")]
  1424. +#[cfg(feature="collections")]
  1425. pub struct Lines<B> {
  1426. buf: B,
  1427. }
  1428. -#[stable(feature = "rust1", since = "1.0.0")]
  1429. +#[cfg(feature="collections")]
  1430. impl<B: BufRead> Iterator for Lines<B> {
  1431. type Item = Result<String>;
  1432. diff --git a/prelude.rs b/prelude.rs
  1433. index 8772d0f..49d66c9 100644
  1434. --- a/prelude.rs
  1435. +++ b/prelude.rs
  1436. @@ -18,7 +18,8 @@
  1437. //! use std::io::prelude::*;
  1438. //! ```
  1439. -#![stable(feature = "rust1", since = "1.0.0")]
  1440. +pub use super::{Read, Write, Seek};
  1441. +#[cfg(feature="collections")] pub use super::BufRead;
  1442. -#[stable(feature = "rust1", since = "1.0.0")]
  1443. -pub use super::{Read, Write, BufRead, Seek};
  1444. +#[cfg(feature="collections")] pub use alloc::boxed::Box;
  1445. +#[cfg(feature="collections")] pub use collections::vec::Vec;
  1446. diff --git a/util.rs b/util.rs
  1447. index e05a0d5..2f03121 100644
  1448. --- a/util.rs
  1449. +++ b/util.rs
  1450. @@ -10,7 +10,8 @@
  1451. #![allow(missing_copy_implementations)]
  1452. -use io::{self, Read, Write, ErrorKind, BufRead};
  1453. +use io::{self, Read, Write, ErrorKind};
  1454. +#[cfg(feature="collections")] use io::BufRead;
  1455. /// Copies the entire contents of a reader into a writer.
  1456. ///
  1457. @@ -42,7 +43,6 @@ use io::{self, Read, Write, ErrorKind, BufRead};
  1458. /// # Ok(())
  1459. /// # }
  1460. /// ```
  1461. -#[stable(feature = "rust1", since = "1.0.0")]
  1462. pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<u64>
  1463. where R: Read, W: Write
  1464. {
  1465. @@ -66,7 +66,6 @@ pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<
  1466. /// the documentation of `empty()` for more details.
  1467. ///
  1468. /// [empty]: fn.empty.html
  1469. -#[stable(feature = "rust1", since = "1.0.0")]
  1470. pub struct Empty { _priv: () }
  1471. /// Constructs a new handle to an empty reader.
  1472. @@ -87,14 +86,12 @@ pub struct Empty { _priv: () }
  1473. /// # Ok(buffer)
  1474. /// # }
  1475. /// ```
  1476. -#[stable(feature = "rust1", since = "1.0.0")]
  1477. pub fn empty() -> Empty { Empty { _priv: () } }
  1478. -#[stable(feature = "rust1", since = "1.0.0")]
  1479. impl Read for Empty {
  1480. fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> { Ok(0) }
  1481. }
  1482. -#[stable(feature = "rust1", since = "1.0.0")]
  1483. +#[cfg(feature="collections")]
  1484. impl BufRead for Empty {
  1485. fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) }
  1486. fn consume(&mut self, _n: usize) {}
  1487. @@ -106,17 +103,14 @@ impl BufRead for Empty {
  1488. /// see the documentation of `repeat()` for more details.
  1489. ///
  1490. /// [repeat]: fn.repeat.html
  1491. -#[stable(feature = "rust1", since = "1.0.0")]
  1492. pub struct Repeat { byte: u8 }
  1493. /// Creates an instance of a reader that infinitely repeats one byte.
  1494. ///
  1495. /// All reads from this reader will succeed by filling the specified buffer with
  1496. /// the given byte.
  1497. -#[stable(feature = "rust1", since = "1.0.0")]
  1498. pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } }
  1499. -#[stable(feature = "rust1", since = "1.0.0")]
  1500. impl Read for Repeat {
  1501. fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
  1502. for slot in &mut *buf {
  1503. @@ -132,17 +126,14 @@ impl Read for Repeat {
  1504. /// see the documentation of `sink()` for more details.
  1505. ///
  1506. /// [sink]: fn.sink.html
  1507. -#[stable(feature = "rust1", since = "1.0.0")]
  1508. pub struct Sink { _priv: () }
  1509. /// Creates an instance of a writer which will successfully consume all data.
  1510. ///
  1511. /// All calls to `write` on the returned instance will return `Ok(buf.len())`
  1512. /// and the contents of the buffer will not be inspected.
  1513. -#[stable(feature = "rust1", since = "1.0.0")]
  1514. pub fn sink() -> Sink { Sink { _priv: () } }
  1515. -#[stable(feature = "rust1", since = "1.0.0")]
  1516. impl Write for Sink {
  1517. fn write(&mut self, buf: &[u8]) -> io::Result<usize> { Ok(buf.len()) }
  1518. fn flush(&mut self) -> io::Result<()> { Ok(()) }