Skip to content

Commit 6a6c44e

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 d5e943b commit 6a6c44e

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/libstd/io/buffered.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,19 @@ impl<W: Read + Write> Read for InternalBufWriter<W> {
435435
/// infrequent calls to `read` and `write` on the underlying `Read+Write`.
436436
///
437437
/// The output buffer will be written out when this stream is dropped.
438-
#[stable(feature = "rust1", since = "1.0.0")]
438+
#[unstable(feature = "buf_stream",
439+
reason = "unsure about semantics of buffering two directions, \
440+
leading to issues like #17136")]
439441
pub struct BufStream<S: Write> {
440442
inner: BufReader<InternalBufWriter<S>>
441443
}
442444

445+
#[unstable(feature = "buf_stream",
446+
reason = "unsure about semantics of buffering two directions, \
447+
leading to issues like #17136")]
443448
impl<S: Read + Write> BufStream<S> {
444449
/// Creates a new buffered stream with explicitly listed capacities for the
445450
/// reader/writer buffer.
446-
#[stable(feature = "rust1", since = "1.0.0")]
447451
pub fn with_capacities(reader_cap: usize, writer_cap: usize, inner: S)
448452
-> BufStream<S> {
449453
let writer = BufWriter::with_capacity(writer_cap, inner);
@@ -454,13 +458,11 @@ impl<S: Read + Write> BufStream<S> {
454458

455459
/// Creates a new buffered stream with the default reader/writer buffer
456460
/// capacities.
457-
#[stable(feature = "rust1", since = "1.0.0")]
458461
pub fn new(inner: S) -> BufStream<S> {
459462
BufStream::with_capacities(DEFAULT_BUF_SIZE, DEFAULT_BUF_SIZE, inner)
460463
}
461464

462465
/// Gets a reference to the underlying stream.
463-
#[stable(feature = "rust1", since = "1.0.0")]
464466
pub fn get_ref(&self) -> &S {
465467
let InternalBufWriter(ref w) = self.inner.inner;
466468
w.get_ref()
@@ -472,7 +474,6 @@ impl<S: Read + Write> BufStream<S> {
472474
///
473475
/// It is inadvisable to read directly from or write directly to the
474476
/// underlying stream.
475-
#[stable(feature = "rust1", since = "1.0.0")]
476477
pub fn get_mut(&mut self) -> &mut S {
477478
let InternalBufWriter(ref mut w) = self.inner.inner;
478479
w.get_mut()
@@ -482,7 +483,6 @@ impl<S: Read + Write> BufStream<S> {
482483
///
483484
/// The internal write buffer is written out before returning the stream.
484485
/// Any leftover data in the read buffer is lost.
485-
#[stable(feature = "rust1", since = "1.0.0")]
486486
pub fn into_inner(self) -> Result<S, IntoInnerError<BufStream<S>>> {
487487
let BufReader { inner: InternalBufWriter(w), buf, pos, cap } = self.inner;
488488
w.into_inner().map_err(|IntoInnerError(w, e)| {
@@ -493,20 +493,26 @@ impl<S: Read + Write> BufStream<S> {
493493
}
494494
}
495495

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

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

509-
#[stable(feature = "rust1", since = "1.0.0")]
513+
#[unstable(feature = "buf_stream",
514+
reason = "unsure about semantics of buffering two directions, \
515+
leading to issues like #17136")]
510516
impl<S: Read + Write> Write for BufStream<S> {
511517
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
512518
self.inner.inner.get_mut().write(buf)
@@ -516,7 +522,9 @@ impl<S: Read + Write> Write for BufStream<S> {
516522
}
517523
}
518524

519-
#[stable(feature = "rust1", since = "1.0.0")]
525+
#[unstable(feature = "buf_stream",
526+
reason = "unsure about semantics of buffering two directions, \
527+
leading to issues like #17136")]
520528
impl<S: Write> fmt::Debug for BufStream<S> where S: fmt::Debug {
521529
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
522530
let reader = &self.inner;

0 commit comments

Comments
 (0)