Skip to content

Commit db477ee

Browse files
committed
std: Destabilize io::BufStream
As pointed out in #17136 the semantics of a `BufStream` aren't always what one expects, and it looks like other [languages like C#][c-sharp] implement a buffered stream with only one underlying buffer. For now this commit destabilizes the primitive in the `std::io` module to give us some more time in figuring out what to do with it. [c-sharp]: https://msdn.microsoft.com/en-us/library/system.io.bufferedstream%28v=vs.110%29.aspx [breaking-change]
1 parent e962870 commit db477ee

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/libstd/io/buffered.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -432,15 +432,19 @@ impl<W: Read + Write> Read for InternalBufWriter<W> {
432432
/// infrequent calls to `read` and `write` on the underlying `Read+Write`.
433433
///
434434
/// The output buffer will be written out when this stream is dropped.
435-
#[stable(feature = "rust1", since = "1.0.0")]
435+
#[unstable(feature = "buf_stream",
436+
reason = "unsure about semantics of buffering two directions, \
437+
leading to issues like #17136")]
436438
pub struct BufStream<S: Write> {
437439
inner: BufReader<InternalBufWriter<S>>
438440
}
439441

442+
#[unstable(feature = "buf_stream",
443+
reason = "unsure about semantics of buffering two directions, \
444+
leading to issues like #17136")]
440445
impl<S: Read + Write> BufStream<S> {
441446
/// Creates a new buffered stream with explicitly listed capacities for the
442447
/// reader/writer buffer.
443-
#[stable(feature = "rust1", since = "1.0.0")]
444448
pub fn with_capacities(reader_cap: usize, writer_cap: usize, inner: S)
445449
-> BufStream<S> {
446450
let writer = BufWriter::with_capacity(writer_cap, inner);
@@ -451,13 +455,11 @@ impl<S: Read + Write> BufStream<S> {
451455

452456
/// Creates a new buffered stream with the default reader/writer buffer
453457
/// capacities.
454-
#[stable(feature = "rust1", since = "1.0.0")]
455458
pub fn new(inner: S) -> BufStream<S> {
456459
BufStream::with_capacities(DEFAULT_BUF_SIZE, DEFAULT_BUF_SIZE, inner)
457460
}
458461

459462
/// Gets a reference to the underlying stream.
460-
#[stable(feature = "rust1", since = "1.0.0")]
461463
pub fn get_ref(&self) -> &S {
462464
let InternalBufWriter(ref w) = self.inner.inner;
463465
w.get_ref()
@@ -469,7 +471,6 @@ impl<S: Read + Write> BufStream<S> {
469471
///
470472
/// It is inadvisable to read directly from or write directly to the
471473
/// underlying stream.
472-
#[stable(feature = "rust1", since = "1.0.0")]
473474
pub fn get_mut(&mut self) -> &mut S {
474475
let InternalBufWriter(ref mut w) = self.inner.inner;
475476
w.get_mut()
@@ -479,7 +480,6 @@ impl<S: Read + Write> BufStream<S> {
479480
///
480481
/// The internal write buffer is written out before returning the stream.
481482
/// Any leftover data in the read buffer is lost.
482-
#[stable(feature = "rust1", since = "1.0.0")]
483483
pub fn into_inner(self) -> Result<S, IntoInnerError<BufStream<S>>> {
484484
let BufReader { inner: InternalBufWriter(w), buf, pos, cap } = self.inner;
485485
w.into_inner().map_err(|IntoInnerError(w, e)| {
@@ -490,20 +490,26 @@ impl<S: Read + Write> BufStream<S> {
490490
}
491491
}
492492

493-
#[stable(feature = "rust1", since = "1.0.0")]
493+
#[unstable(feature = "buf_stream",
494+
reason = "unsure about semantics of buffering two directions, \
495+
leading to issues like #17136")]
494496
impl<S: Read + Write> BufRead for BufStream<S> {
495497
fn fill_buf(&mut self) -> io::Result<&[u8]> { self.inner.fill_buf() }
496498
fn consume(&mut self, amt: usize) { self.inner.consume(amt) }
497499
}
498500

499-
#[stable(feature = "rust1", since = "1.0.0")]
501+
#[unstable(feature = "buf_stream",
502+
reason = "unsure about semantics of buffering two directions, \
503+
leading to issues like #17136")]
500504
impl<S: Read + Write> Read for BufStream<S> {
501505
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
502506
self.inner.read(buf)
503507
}
504508
}
505509

506-
#[stable(feature = "rust1", since = "1.0.0")]
510+
#[unstable(feature = "buf_stream",
511+
reason = "unsure about semantics of buffering two directions, \
512+
leading to issues like #17136")]
507513
impl<S: Read + Write> Write for BufStream<S> {
508514
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
509515
self.inner.inner.get_mut().write(buf)
@@ -513,7 +519,9 @@ impl<S: Read + Write> Write for BufStream<S> {
513519
}
514520
}
515521

516-
#[stable(feature = "rust1", since = "1.0.0")]
522+
#[unstable(feature = "buf_stream",
523+
reason = "unsure about semantics of buffering two directions, \
524+
leading to issues like #17136")]
517525
impl<S: Write> fmt::Debug for BufStream<S> where S: fmt::Debug {
518526
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
519527
let reader = &self.inner;

0 commit comments

Comments
 (0)