about summary refs log tree commit diff
path: root/library/std/src/io/buffered/bufwriter.rs
AgeCommit message (Collapse)AuthorLines
2025-08-26remove deprecated Error::description in implsMarijn Schouten-10/+2
2024-11-26std: update internal uses of `io::const_error!`joboet-2/+2
2024-09-24Pre-allocate buffers in `File::open_buffered` and `create_buffered`Josh Stone-0/+10
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-3/+1
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-14std: Unsafe-wrap std::ioJubilee Young-3/+5
2024-07-12Use ManuallyDrop in BufWriter::into_partsBen Kimock-7/+7
2024-03-03Fix quadratic behavior of repeated vectored writesJan Verbeek-24/+27
Some implementations of `Write::write_vectored` in the standard library (`BufWriter`, `LineWriter`, `Stdout`, `Stderr`) check all buffers to calculate the total length. This is O(n) over the number of buffers. It's common that only a limited number of buffers is written at a time (e.g. 1024 for `writev(2)`). `write_vectored_all` will then call `write_vectored` repeatedly, leading to a runtime of O(n²) over the number of buffers. The fix is to only calculate as much as needed if it's needed.
2024-02-19Remove an old hack for rustdocPavel Grigorenko-2/+1
2023-09-03Use std::io::Error::is_interrupted everywhereBen Kimock-1/+1
2023-07-06Rollup merge of #112008 - intruder-kat:master, r=NilstriebMichael Goulet-1/+1
Fix incorrect documented default bufsize in bufreader/writer
2023-05-26Fix incorrect documented default bufsize in bufreader/writerKathryn R-1/+1
2023-05-01Relax implicit `W: Sized` bound on `BufWriter<W>`Maybe Waffle-68/+70
2023-04-06Remove an unnecessary `mut` in `BufWriter::into_parts`.管唯宇-1/+1
`ptr::read` takes `*const T` so `&mut` is not necessary.
2022-06-19Fix documentation for with_capacity and reserve families of methodsjmaargh-2/+2
Documentation for the following methods with_capacity with_capacity_in with_capacity_and_hasher reserve reserve_exact try_reserve try_reserve_exact was inconsistent and often not entirely correct where they existed on the following types Vec VecDeque String OsString PathBuf BinaryHeap HashSet HashMap BufWriter LineWriter since the allocator is allowed to allocate more than the requested capacity in all such cases, and will frequently "allocate" much more in the case of zero-sized types (I also checked BufReader, but there the docs appear to be accurate as it appears to actually allocate the exact capacity). Some effort was made to make the documentation more consistent between types as well. Fix with_capacity* methods for Vec Fix *reserve* methods for Vec Fix docs for *reserve* methods of VecDeque Fix docs for String::with_capacity Fix docs for *reserve* methods of String Fix docs for OsString::with_capacity Fix docs for *reserve* methods on OsString Fix docs for with_capacity* methods on HashSet Fix docs for *reserve methods of HashSet Fix docs for with_capacity* methods of HashMap Fix docs for *reserve methods on HashMap Fix expect messages about OOM in doctests Fix docs for BinaryHeap::with_capacity Fix docs for *reserve* methods of BinaryHeap Fix typos Fix docs for with_capacity on BufWriter and LineWriter Fix consistent use of `hasher` between `HashMap` and `HashSet` Fix warning in doc test Add test for capacity of vec with ZST Fix doc test error
2022-02-04Hide Repr details from io::Error, and rework `io::Error::new_const`.Thom Chiovoloni-3/+3
2021-10-10Add #[must_use] to conversions that move selfJohn Kugelman-0/+1
2021-09-25Apply 16 commits (squashed)Frank Steffahn-1/+1
---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::fmt ---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::{rc, sync} ---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::string ---------- Fix spacing for links inside code blocks in alloc::vec ---------- Fix spacing for links inside code blocks in core::option ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in core::result ---------- Fix spacing for links inside code blocks in core::{iter::{self, iterator}, stream::stream, poll} ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in std::{fs, path} ---------- Fix spacing for links inside code blocks in std::{collections, time} ---------- Fix spacing for links inside code blocks in and make formatting of `&str`-like types consistent in std::ffi::{c_str, os_str} ---------- Fix spacing for links inside code blocks, and improve link tooltips in std::ffi ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in std::{io::{self, buffered::{bufreader, bufwriter}, cursor, util}, net::{self, addr}} ---------- Fix typo in link to `into` for `OsString` docs ---------- Remove tooltips that will probably become redundant in the future ---------- Apply suggestions from code review Replacing `…std/primitive.reference.html` paths with just `reference` Co-authored-by: Joshua Nelson <github@jyn.dev> ---------- Also replace `…std/primitive.reference.html` paths with just `reference` in `core::pin`
2021-08-24Stabilise BufWriter::into_partsIan Jackson-8/+6
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-29Rename feature gate bufwriter_into_parts from bufwriter_into_raw_partsIan Jackson-8/+8
As requested https://github.com/rust-lang/rust/pull/85901#pullrequestreview-698404772 Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-29BufWriter: rename `into_parts` from `into_raw_parts`Ian Jackson-6/+6
I looked in stdlib and as @BurntSushi thought, `raw` is generally used for raw pointers, or other hazardous kinds of thing. stdlib does not have `into_parts` apart from the one I added to `IntoInnerError`. I did an ad-hoc search of the rustdocs for my current game project Otter, which includes quite a large number of dependencies. `into_parts` seems heavily used for things quite like this. So change this name. Suggested-by: Andrew Gallant <jamslam@gmail.com> Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-22Remove Option from BufWriterAlex Macleod-10/+14
Fixes #72925
2021-04-13BufWriter: improve safety commentTyson Nottingham-6/+10
2021-04-13BufWriter: simplify buffer drainingTyson Nottingham-5/+1
2021-04-13BufWriter: use #[cold] and less aggressive #[inline] hintsTyson Nottingham-1/+3
2021-04-13BufWriter: handle possibility of overflowTyson Nottingham-15/+39
2021-04-13BufWriter: optimize for write sizes less than buffer sizeTyson Nottingham-24/+32
Optimize for the common case where the input write size is less than the buffer size. This slightly increases the cost for pathological write patterns that commonly fill the buffer exactly, but if a client is doing that frequently, they're already paying the cost of frequent flushing, etc., so the cost is of this optimization to them is relatively small.
2021-04-13BufWriter: avoid using expensive Vec methodsTyson Nottingham-12/+75
We use a Vec as our internal, constant-sized buffer, but the overhead of using methods like `extend_from_slice` can be enormous, likely because they don't get inlined, because `Vec` has to repeat bounds checks that we've already done, and because it makes considerations for things like reallocating, even though they should never happen.
2021-04-13BufWriter: apply #[inline] / #[inline(never)] optimizationsTyson Nottingham-24/+66
Ensure that `write` and `write_all` can be inlined and that their commonly executed fast paths can be as short as possible. `write_vectored` would likely benefit from the same optimization, but I omitted it because its implementation is more complex, and I don't have a benchmark on hand to guide its optimization.
2021-03-21Use io::Error::new_const everywhere to avoid allocations.Mara Bos-2/+2
2021-01-31specialize io::copy to use the memory of the writer if it is a BufWriterThe8472-1/+13
2021-01-19Auto merge of #79705 - ijackson:bufwriter-disassemble, r=m-ou-sebors-0/+99
BufWriter: Provide into_raw_parts If something goes wrong, one might want to unpeel the layers of nested Writers to perform recovery actions on the underlying writer, or reuse its resources. `into_inner` can be used for this when the inner writer is still working. But when the inner writer is broken, and returning errors, `into_inner` simply gives you the error from flush, and the same `Bufwriter` back again. Here I provide the necessary function, which I have chosen to call `into_raw_parts`. I had to do something with `panicked`. Returning it to the caller as a boolean seemed rather bare. Throwing the buffered data away in this situation also seems unfriendly: maybe the programmer knows something about the underlying writer and can recover somehow. So I went for a custom Error. This may be overkill, but it does have the nice property that a caller who actually wants to look at the buffered data, rather than simply extracting the inner writer, will be told by the type system if they forget to handle the panicked case. If a caller doesn't need the buffer, it can just be discarded. That WriterPanicked is a newtype around Vec<u8> means that hopefully the layouts of the Ok and Err variants can be very similar, with just a boolean discriminant. So this custom error type should compile down to nearly no code. *If this general idea is felt appropriate, I will open a tracking issue, etc.*
2021-01-04BufWriter::into_raw_parts: Add tracking issue numberIan Jackson-6/+6
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-12-12fixup! WriterPanicked: Use debug_structIan Jackson-1/+1
2020-12-12WriterPanicked: Use debug_structIan Jackson-1/+3
Co-authored-by: Ivan Tham <pickfire@riseup.net>
2020-12-12bufwriter::WriterPanicked: Provide panicking exampleIan Jackson-0/+24
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-12-04BufWriter: Provide into_raw_partsIan Jackson-0/+73
If something goes wrong, one might want to unpeel the layers of nested Writers to perform recovery actions on the underlying writer, or reuse its resources. `into_inner` can be used for this when the inner writer is still working. But when the inner writer is broken, and returning errors, `into_inner` simply gives you the error from flush, and the same `Bufwriter` back again. Here I provide the necessary function, which I have chosen to call `into_raw_parts`. I had to do something with `panicked`. Returning it to the caller as a boolean seemed rather bare. Throwing the buffered data away in this situation also seems unfriendly: maybe the programmer knows something about the underlying writer and can recover somehow. So I went for a custom Error. This may be overkill, but it does have the nice property that a caller who actually wants to look at the buffered data, rather than simply extracting the inner writer, will be told by the type system if they forget to handle the panicked case. If a caller doesn't need the buffer, it can just be discarded. That WriterPanicked is a newtype around Vec<u8> means that hopefully the layouts of the Ok and Err variants can be very similar, with just a boolean discriminant. So this custom error type should compile down to nearly no code. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-11-22Reduce branching in write_vectored for BufWriterMikhail Zabaluev-14/+9
Do what write does and optimize for the most likely case: slices are much smaller than the buffer. If a slice does not fit completely in the remaining capacity of the buffer, it is left out rather than buffered partially. Special treatment is only left for oversized slices that are written directly to the underlying writer.
2020-11-22Make is_write_vectored return true for BufWriterMikhail Zabaluev-1/+1
BufWriter provides an efficient implementation of write_vectored also when the underlying writer does not support vectored writes.
2020-11-22Optimize write_vectored for BufWriterMikhail Zabaluev-12/+50
If the underlying writer does not support efficient vectored output, do it differently: always try to coalesce the slices in the buffer until one comes that does not fit entirely. Flush the buffer before the first slice if needed.
2020-11-05document HACKsPeter Jaszkowiak-0/+1
2020-11-05Intra-doc links for std::io::bufferedPeter Jaszkowiak-2/+2
2020-10-26fix(docs): typo in BufWriter documentationMichele Lacchia-1/+1
2020-09-10Refactor io/buffered.rs into submodulesNathan West-0/+387