f1e191c0b959111aef19f3aa06b7f1743419470c.patch 56 KB

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