b81da278623d9dcda1776008612bd42e1922e9c3.patch 57 KB

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