Skip to content

Commit eae692e

Browse files
committed
Auto merge of #25009 - alexcrichton:less-buffered-stream, r=aturon
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]
2 parents 6cd7486 + db477ee commit eae692e

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
@@ -433,15 +433,19 @@ impl<W: Read + Write> Read for InternalBufWriter<W> {
433433
/// infrequent calls to `read` and `write` on the underlying `Read+Write`.
434434
///
435435
/// The output buffer will be written out when this stream is dropped.
436-
#[stable(feature = "rust1", since = "1.0.0")]
436+
#[unstable(feature = "buf_stream",
437+
reason = "unsure about semantics of buffering two directions, \
438+
leading to issues like #17136")]
437439
pub struct BufStream<S: Write> {
438440
inner: BufReader<InternalBufWriter<S>>
439441
}
440442

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

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

460463
/// Gets a reference to the underlying stream.
461-
#[stable(feature = "rust1", since = "1.0.0")]
462464
pub fn get_ref(&self) -> &S {
463465
let InternalBufWriter(ref w) = self.inner.inner;
464466
w.get_ref()
@@ -470,7 +472,6 @@ impl<S: Read + Write> BufStream<S> {
470472
///
471473
/// It is inadvisable to read directly from or write directly to the
472474
/// underlying stream.
473-
#[stable(feature = "rust1", since = "1.0.0")]
474475
pub fn get_mut(&mut self) -> &mut S {
475476
let InternalBufWriter(ref mut w) = self.inner.inner;
476477
w.get_mut()
@@ -480,7 +481,6 @@ impl<S: Read + Write> BufStream<S> {
480481
///
481482
/// The internal write buffer is written out before returning the stream.
482483
/// Any leftover data in the read buffer is lost.
483-
#[stable(feature = "rust1", since = "1.0.0")]
484484
pub fn into_inner(self) -> Result<S, IntoInnerError<BufStream<S>>> {
485485
let BufReader { inner: InternalBufWriter(w), buf, pos, cap } = self.inner;
486486
w.into_inner().map_err(|IntoInnerError(w, e)| {
@@ -491,20 +491,26 @@ impl<S: Read + Write> BufStream<S> {
491491
}
492492
}
493493

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

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

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

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

0 commit comments

Comments
 (0)