8d06332a27b020f5252238946fa9dccc3843d52a.patch 50 KB

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