about summary refs log tree commit diff
path: root/library/std/src/io/copy.rs
AgeCommit message (Collapse)AuthorLines
2025-08-16library: Migrate from `cfg_if` to `cfg_select`Josh Triplett-3/+4
Migrate the standard library from using the external `cfg_if` crate to using the now-built-in `cfg_select` macro. This does not yet eliminate the dependency from `library/std/Cargo.toml`, because while the standard library itself no longer uses `cfg_if`, it also incorporates the `backtrace` crate, which does. Migration assisted by the following vim command (after selecting the full `cfg_if!` invocation): ``` '<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e ``` This is imperfect, but substantially accelerated the process. This prompts for confirmation on the `} else {` since that can also appear inside one of the arms. This also requires manual intervention to handle any multi-line conditions.
2025-04-01io: Avoid marking buffer as uninit when copying to `BufWriter`Benoît du Garreau-1/+4
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2023-11-26unify read_to_end and io::copy impls for reading into a VecThe 8472-66/+3
2023-11-04detect EOF earlierThe 8472-5/+7
The initial probe-for-empty-source by stack_buffer_copy only detected EOF if the source was empty but not when it was merely small which lead to additional calls to read() after Ok(0) had already been returned in the stack copy routine
2023-11-04avoid excessive initialization when copying to a VecThe 8472-17/+47
It now keeps track of initialized bytes to avoid reinitialization. It also keeps track of read sizes to avoid initializing more bytes than the reader needs. This is important when passing a huge vector to a Read that only has a few bytes to offer and doesn't implement read_buf().
2023-09-03Use std::io::Error::is_interrupted everywhereBen Kimock-5/+6
2023-07-09additional io::copy specializationsThe 8472-2/+79
- copying from `&[u8]` and `VecDeque<u8>` - copying to `Vec<u8>`
2023-06-17Extend io::copy buffer reuse to BufReader tooThe 8472-13/+97
previously it was only able to use BufWriter. This was due to a limitation in the BufReader generics that prevented specialization. This change works around the issue by using `where Self: Read` instead of `where I: Read`. This limits our options, e.g. we can't access BufRead methods, but it happens to work out if we rely on some implementation details.
2023-06-16Rollup merge of #111074 - WaffleLapkin:🌟unsizes_your_buf_reader🌟, ↵Michael Goulet-1/+1
r=Amanieu Relax implicit `T: Sized` bounds on `BufReader<T>`, `BufWriter<T>` and `LineWriter<T>` TL;DR: ```diff,rust -pub struct BufReader<R> { /* ... */ } +pub struct BufReader<R: ?Sized> { /* ... */ } -pub struct BufWriter<W: Write> { /* ... */ } +pub struct BufWriter<W: ?Sized + Write> { /* ... */ } -pub struct LineWriter<W: Write> { /* ... */ } +pub struct LineWriter<W: ?Sized + Write> { /* ... */ } ``` This allows using `&mut BufReader<dyn Read>`, for example. **This is an insta-stable change**.
2023-05-15wanting => wantVagelis Prokopiou-1/+1
2023-05-01Relax implicit `W: Sized` bound on `BufWriter<W>`Maybe Waffle-1/+1
2022-08-18Address reviewer commentsNick Cameron-1/+1
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-05non-linux platformsNick Cameron-4/+4
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-04std::io: migrate ReadBuf to BorrowBuf/BorrowCursorNick Cameron-16/+18
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-03-29Warn that platform-specific behavior may changeMartin Pool-0/+4
2022-03-24Document Linux kernel handoff in std::io::copy and std::fs::copyMartin Pool-0/+6
2021-11-02fix test failure from trying to assume_init too muchDrMeepster-1/+1
2021-11-02Don't reinitialize hereDrMeepster-1/+8
2021-11-02read_bufDrMeepster-43/+31
2021-02-24library: Normalize safety-for-unsafe-block commentsMiguel Ojeda-1/+1
Almost all safety comments are of the form `// SAFETY:`, so normalize the rest and fix a few of them that should have been a `/// # Safety` section instead. Furthermore, make `tidy` only allow the uppercase form. While currently `tidy` only checks `core`, it is a good idea to prevent `core` from drifting to non-uppercase comments, so that later we can start checking `alloc` etc. too. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-01-31specialize io::copy to use the memory of the writer if it is a BufWriterThe8472-6/+74
2020-11-13limit visibility of copy offload helpers to sys::unix moduleThe8472-3/+0
2020-11-13move copy specialization tests to their own moduleThe8472-0/+3
2020-11-13move copy specialization into sys::unix moduleThe8472-377/+8
2020-11-13reduce syscalls by inferring FD types based on source struct instead of ↵The8472-66/+102
calling stat() also adds handling for edge-cases involving large sparse files where sendfile could fail with EOVERFLOW
2020-11-13add forwarding specializations for &mut variantsThe8472-0/+21
`impl Write for &mut T where T: Write`, thus the same should apply to the specialization traits
2020-11-13prioritize sendfile over splice since it results in fewer context switches ↵The8472-16/+16
when sending to pipes splice returns to userspace when the pipe is full, sendfile just blocks until it's done, this can achieve much higher throughput
2020-11-13move tests module into separate fileThe8472-56/+0
2020-11-13specialize io::copy to use copy_file_range, splice or sendfileThe8472-0/+456
Currently it only applies to linux systems. It can be extended to make use of similar syscalls on other unix systems.