about summary refs log tree commit diff
path: root/src/libstd/io/buffered.rs
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-1703/+0
2020-06-28Fix docstring typoCaleb Hattingh-1/+1
2020-06-10Migrate to numeric associated constsLzu Tao-5/+5
2020-06-03Stabilize `std::io::Buf{Reader, Writer}::capacity`Yuki Okushi-4/+2
2020-04-26Update nameSteven Fackler-4/+4
2020-04-26Add Read/Write::can_read/write_vectoredSteven Fackler-0/+8
When working with an arbitrary reader or writer, code that uses vectored operations may end up being slower than code that copies into a single buffer when the underlying reader or writer doesn't actually support vectored operations. These new methods allow you to ask the reader or witer up front if vectored operations are efficiently supported. Currently, you have to use some heuristics to guess by e.g. checking if the read or write only accessed the first buffer. Hyper is one concrete example of a library that has to do this dynamically: https://github.com/hyperium/hyper/blob/0eaf304644a396895a4ce1f0146e596640bb666a/src/proto/h1/io.rs#L582-L594
2020-04-24Replace filter_map().next() calls with find_map()Josh Stone-9/+4
These are semantically the same, but `find_map()` is more concise.
2020-02-05Fix issue number of `capacity` methodYuki Okushi-2/+2
2020-01-28Add capacity to BufReader with same unstable gateAndreas Molzer-0/+26
2020-01-26Add a method to query the capacity of a BufWriterAndreas Molzer-0/+19
2020-01-02Use drop instead of the toilet closure `|_| ()`Lzu Tao-1/+1
2019-12-24Deprecate Error::description for realDavid Tolnay-0/+1
`description` has been documented as soft-deprecated since 1.27.0 (17 months ago). There is no longer any reason to call it or implement it. This commit: - adds #[rustc_deprecated(since = "1.41.0")] to Error::description; - moves description (and cause, which is also deprecated) below the source and backtrace methods in the Error trait; - reduces documentation of description and cause to take up much less vertical real estate in rustdocs, while preserving the example that shows how to render errors without needing to call description; - removes the description function of all *currently unstable* Error impls in the standard library; - marks #[allow(deprecated)] the description function of all *stable* Error impls in the standard library; - replaces miscellaneous uses of description in example code and the compiler.
2019-12-22Format the worldMark Rousskov-2/+2
2019-12-12std: Implement `LineWriter::write_vectored`Alex Crichton-1/+171
This commit implements the `write_vectored` method of the `LineWriter` type. First discovered in bytecodealliance/wasmtime#629 the `write_vectored` method of `Stdout` bottoms out here but only ends up writing the first buffer due to the default implementation of `write_vectored`. Like `BufWriter`, however, `LineWriter` can have a non-default implementation of `write_vectored` which tries to preserve the vectored-ness as much as possible. Namely we can have a vectored write for everything before the newline and everything after the newline if all the stars align well. Also like `BufWriter`, though, special care is taken to ensure that whenever bytes are written we're sure to signal success since that represents a "commit" of writing bytes.
2019-11-29Format libstd with rustfmtDavid Tolnay-67/+80
This commit applies rustfmt with rust-lang/rust's default settings to files in src/libstd *that are not involved in any currently open PR* to minimize merge conflicts. THe list of files involved in open PRs was determined by querying GitHub's GraphQL API with this script: https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8 With the list of files from the script in outstanding_files, the relevant commands were: $ find src/libstd -name '*.rs' \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ rg libstd outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of libstd. To confirm no funny business: $ git checkout $THIS_COMMIT^ $ git show --pretty= --name-only $THIS_COMMIT \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ git diff $THIS_COMMIT # there should be no difference
2019-11-08docs: Fix link to BufWriter::flushBryan Burgers-1/+1
One of the links in the docs was being rendered as a literal open-bracket followed by a single quote, instead of being transformed into a link. Fix it to match the link earlier in the same paragraph.
2019-10-31rephrase sentence regarding data loss when using BufReader::into_innerMarco Conte-2/+3
2019-10-31enhance the documentation of std::io::BufReader regarding potential data lossMarco Conte-2/+4
2019-08-31clarify that not all errors are observedJohn Erickson-2/+3
2019-08-31Add in generic type to description of BufReader and BufWriterJohn Erickson-17/+17
2019-08-31Update BufWriter example to include call to flush()John Erickson-6/+7
2019-05-29Rollup merge of #61235 - lzutao:stabilize-bufreader_buffer, r=CentrilMazdak Farrokhzad-4/+2
Stabilize bufreader_buffer feature FCP done in https://github.com/rust-lang/rust/issues/45323#issuecomment-495937047 Closes #45323 r? @SimonSapin
2019-05-27Stabilize bufreader_buffer featureLzu Tao-4/+2
2019-05-25Annotate test with #[test]Chris Gregory-0/+1
2019-05-25Add test that impl Seek for BufReader correctly invalidates buffer between seeksChris Gregory-0/+34
2019-05-04Fix intra-doc link resolution failure on re-exporting libstdTaiki Endo-1/+1
2019-04-29Rollup merge of #60334 - sfackler:stable-iovec, r=alexcrichtonMazdak Farrokhzad-3/+4
Stabilized vectored IO This renames `std::io::IoVec` to `std::io::IoSlice` and `std::io::IoVecMut` to `std::io::IoSliceMut`, and stabilizes `std::io::IoSlice`, `std::io::IoSliceMut`, `std::io::Read::read_vectored`, and `std::io::Write::write_vectored`. Closes #58452 r? @alexcrichton
2019-04-27tidySteven Fackler-1/+2
2019-04-27Stabilized vectored IOSteven Fackler-3/+3
This renames `std::io::IoVec` to `std::io::IoSlice` and `std::io::IoVecMut` to `std::io::IoSliceMut`, and stabilizes `std::io::IoSlice`, `std::io::IoSliceMut`, `std::io::Read::read_vectored`, and `std::io::Write::write_vectored`. Closes #58452
2019-04-26Use "capacity" as parameter name in with_capacity() methodsMatthias Geier-7/+7
Closes #60271.
2019-04-11Make BufWriter use get_mut instead of manipulating inner in Write implementationChris Gregory-2/+2
get_mut allows us to abstract over the implementation detail of inner being optional.
2019-03-31libstd: deny(elided_lifetimes_in_paths)Mazdak Farrokhzad-4/+4
2019-03-28Rollup merge of #59474 - czipperz:bufwriter-fix-link-capitalization, r=CentrilMazdak Farrokhzad-2/+2
Fix link capitalization in documentation of std::io::BufWriter.
2019-03-27Fix link capitalization in documentation of std::io::BufWriter.Chris Gregory-2/+2
2019-03-27Document that `std::io::BufReader` discards contents on dropChris Gregory-0/+4
Resolves #55546
2019-03-21Auto merge of #58913 - Milack27:patch_buf_reader, r=joshtriplettbors-2/+45
Add new test case for possible bug in BufReader When reading a large chunk from a BufReader, if all the bytes from the buffer have been already consumed, the internal buffer is bypassed entirely. However, it is not invalidated, and it's possible to access its contents using the `seek_relative` method, because it tries to reuse the existing buffer.
2019-03-06Fix buffer invalidation at BufReader.read_vectoredAndré Vicente Milack-9/+11
2019-03-06Fix buffer invalidation for BufReadAndré Vicente Milack-2/+43
There are two moments when a BufRead object needs to empty it's internal buffer: - In a seek call; - In a read call when all data in the internal buffer had been already consumed and the output buffer has a greater or equal size than the internal buffer. In both cases, the buffer was not being properly emptied, but only marked as consumed (self.pos = self.cap). That should be no problem if the inner reader is only Read, but if it is Seek as well, then it's possible to access the data in the buffer by using the seek_relative method. In order to prevent this from happening, both self.pos and self.cap should be set to 0. Two test cases were added to detect that failure: - test_buffered_reader_invalidated_after_read - test_buffered_reader_invalidated_after_seek Both tests are very similar to each other. The inner reader contains the following data: [5, 6, 7, 0, 1, 2, 3, 4]. The buffer capacity is 3 bytes. - First, we call fill_buffer, which loads [5, 6, 7] into the internal buffer, and then consume those 3 bytes. - Then we either read the 5 remaining bytes in a single read call or we move to the end of the stream by calling seek. In both cases the buffer should be emptied to prevent the previous data [5, 6, 7] from being read. - We now call seek_relative(-2) and read two bytes, which should give us the last 2 bytes of the stream: [3, 4]. Before this commit, the the seek_relative method would consider that we're still in the range of the internal buffer, so instead of fetching data from the inner reader, it would return the two last bytes that were incorrectly still in the buffer: [6, 7]. Therefore, the test would fail. Now, when seek_relative is called the buffer is empty. So the expected data [3, 4] is fetched from the inner reader and the test passes.
2019-03-05Auto merge of #58423 - nox:relax-bounds-buf-reader, r=dtolnaybors-0/+2
Relax Read bounds on a bunch of BufReader<R> methods
2019-02-28libstd => 2018Taiki Endo-11/+10
2019-02-26Auto merge of #58357 - sfackler:vectored-io, r=alexcrichtonbors-2/+31
Add vectored read and write support This functionality has lived for a while in the tokio ecosystem, where it can improve performance by minimizing copies. r? @alexcrichton
2019-02-20Rollup merge of #58553 - scottmcm:more-ihle, r=Centrilkennytm-1/+1
Use more impl header lifetime elision Inspired by seeing explicit lifetimes on these two: - https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html#impl-FusedIterator - https://doc.rust-lang.org/nightly/std/primitive.u32.html#impl-Not And a follow-up to https://github.com/rust-lang/rust/pull/54687, that started using IHLE in libcore. Most of the changes in here fall into two big categories: - Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop`, `Debug`, and `Clone`) - Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`) I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations [where the flipped one cannot elide the lifetime](https://internals.rust-lang.org/t/impl-type-parameter-aliases/9403/2?u=scottmcm). I also removed two lifetimes that turned out to be completely unused; see https://github.com/rust-lang/rust/issues/41960#issuecomment-464557423
2019-02-17Use more impl header lifetime elisionScott McMurray-1/+1
There are two big categories of changes in here - Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop` & `Debug`) - Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`) I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations where the flipped one cannot elide the lifetime.
2019-02-13impl Deref/DerefMut for IoVec typesSteven Fackler-2/+2
Returning &'a mut [u8] was unsound, and we may as well just have them directly deref to their slices to make it easier to work with them.
2019-02-13Add vectored read and write supportSteven Fackler-2/+31
This functionality has lived for a while in the tokio ecosystem, where it can improve performance by minimizing copies.
2019-02-13Relax Read bounds on a bunch of BufReader<R> methodsAnthony Ramine-0/+2
2019-02-10tests: doc commentsAlexander Regueiro-4/+4
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-17deny intra-doc link resolution failures in libstdAndy Russell-1/+4
2018-12-04Replace usages of `..i + 1` ranges with `..=i`.Corey Farwell-1/+1