summary refs log tree commit diff
path: root/library/std/src/io/mod.rs
AgeCommit message (Collapse)AuthorLines
2023-11-09Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io`John Millikin-2/+1
Assigned new feature name `core_io_borrowed_buf` to distinguish from the `Read::read_buf` functionality in `std::io`.
2023-10-27Hide internal methods from documentationJacob Pratt-0/+1
2023-10-23Fix invalid stability attribute features in standard libraryDavid Tolnay-4/+4
2023-10-20Specialize `Bytes<R>::next` when `R` is a `BufReader`.Nicholas Nethercote-10/+40
This reduces the runtime for a simple program using `Bytes::next` to iterate through a file from 220ms to 70ms on my Linux box.
2023-10-16Inline `Bytes::next` and `Bytes::size_hint`.Nicholas Nethercote-0/+2
This greatly increases its speed.
2023-10-07Remove unnecessary tmp variable in default_read_exactWilfred Hughes-2/+1
This variable seems to serve no purpose, and it's a little confusing when reading std source code, so remove it.
2023-10-05Add more diagnostic items for clippyJason Newcomb-0/+2
2023-09-23Avoid overflow in `IoSlice::advance_slices`Eduardo Sánchez Muñoz-16/+19
2023-09-22Auto merge of #114780 - RalfJung:io-safety, r=Amanieubors-1/+47
add more explicit I/O safety documentation Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/434 Cc https://github.com/rust-lang/rust/issues/114167 Cc `@Manishearth` `@sunfishcode` `@joshtriplett`
2023-09-03Use std::io::Error::is_interrupted everywhereBen Kimock-1/+1
2023-08-29further expand on Arc and Box analogyRalf Jung-3/+6
2023-08-25Add a new helper to avoid calling io::Error::kindBen Kimock-7/+7
2023-08-22clarify what you cannot doRalf Jung-3/+3
2023-08-22typos and wordingRalf Jung-3/+3
Co-authored-by: Dan Gohman <dev@sunfishcode.online>
2023-08-16Partially revert #107200Josh Triplett-3/+3
`Ok(0)` is indeed something the caller may interpret as an error, but that's the *correct* thing to return if the writer can't accept any more bytes.
2023-08-14reference-counting analogyRalf Jung-20/+23
2023-08-14reword the paragraph on file description ownershipRalf Jung-9/+10
2023-08-14don't link to RFCs, they are not up-to-date docsRalf Jung-2/+1
2023-08-14wording; and explain some of the possible consequences of violating io-safetyRalf Jung-1/+7
2023-08-14typosRalf Jung-1/+1
2023-08-13add more explicit I/O safety documentationRalf Jung-1/+35
2023-06-18Rollup merge of #107200 - mina86:c, r=AmanieuMatthias Krüger-5/+6
io: soften ‘at most one write attempt’ requirement in io::Write::write At the moment, documentation of std::io::Write::write indicates that call to it ‘represents at most one attempt to write to any wrapped object’. It seems that such wording was put there to contrast it with pre-1.0 interface which attempted to write all the data (it has since been changed in [RFC 517]). However, the requirement puts unnecessary constraints and may complicate adaptors which perform non-trivial transformations on the data. For example, they may maintain an internal buffer which needs to be written out before the write method accepts more data. It might be natural to code the method such that it flushes the buffer and then grabs another chunk of user data. With the current wording in the documentation, the adaptor would be forced to return Ok(0). This commit softens the wording such that implementations can choose code structure which makes most sense for their particular use case. While at it, elaborate on the meaning of `Ok(0)` return pointing out that the write_all methods interprets it as an error. [RFC 517]: https://rust-lang.github.io/rfcs/0517-io-os-reform.html
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-25Clarify safety concern of `io::Read::read` is only relevant in unsafe codeZiru Niu-3/+4
2023-05-01Relax implicit `R: Sized` bound on `BufReader<R>`Maybe Waffle-1/+1
2023-04-28replace version placeholdersPietro Albini-1/+1
2023-04-23Auto merge of #110655 - ChrisDenton:read-to-end, r=joshtriplettbors-5/+19
Limit read size in `File::read_to_end` loop Fixes #110650. Windows file reads have perf overhead that's proportional to the buffer size. When we have a reasonable expectation that we know the file size, we can set a reasonable upper bound for the size of the buffer in one read call.
2023-04-21Limit read size in `File::read_to_end` loopChris Denton-5/+19
This works around performance issues on Windows by limiting reads the size of reads when the expected size is known.
2023-04-20More `mem::take` in `library`Scott McMurray-3/+3
A bunch of places were using `replace(…, &mut [])`, but that can just be `take`.
2023-04-10Stabilize IsTerminalJosh Triplett-1/+1
closes: https://github.com/rust-lang/rust/issues/98070
2023-03-11read_buf_exact: on error, all read bytes are appended to the bufferTomasz Miąsko-2/+16
Guarantee that when `read_buf_exact` returns, all bytes read will be appended to the buffer. Including the case when the operations fails. The motivating use case are operations on a non-blocking reader. When `read_buf_exact` fails with `ErrorKind::WouldBlock` error, the operation can be resumed at a later time.
2023-03-03Update library/std/src/io/mod.rsMichal Nazarewicz-1/+1
Co-authored-by: Jacob Lifshay <programmerjake@gmail.com>
2023-03-01Update library/std/src/io/mod.rsMichal Nazarewicz-3/+3
Co-authored-by: Andrew Gallant <jamslam@gmail.com>
2023-02-08std: add tracking issue for `RawOsError`joboet-1/+1
2023-02-03Update library/std/src/io/mod.rsMichal Nazarewicz-4/+4
2023-01-31std: add type alias for raw OS errorsjoboet-0/+2
Implement rust-lang/libs-team#173.
2023-01-24io: soften ‘at most one write attempt’ requirement in io::Write::writeMichal Nazarewicz-5/+6
At the moment, documentation of std::io::Write::write indicates that call to it ‘represents at most one attempt to write to any wrapped object’. It seems that such wording was put there to contrast it with pre-1.0 interface which attempted to write all the data (it has since been changed in [RFC 517]). However, the requirement puts unnecessary constraints and may complicate adaptors which perform non-trivial transformations on the data. For example, they may maintain an internal buffer which needs to be written out before the write method accepts more data. It might be natural to code the method such that it flushes the buffer and then grabs another chunk of user data. With the current wording in the documentation, the adaptor would be forced to return Ok(0). This commit softens the wording such that implementations can choose code structure which makes most sense for their particular use case. While at it, elaborate on the meaning of `Ok(0)` return pointing out that the write_all methods interprets it as an error. [RFC 517]: https://rust-lang.github.io/rfcs/0517-io-os-reform.html
2023-01-01Document a way to limit read_line lengthKornel-2/+3
2023-01-01Document read_line gotchaKornel-2/+5
2022-10-24Fix grammar in docs for std::io::ReadJesse Ruderman-2/+2
2022-10-15Add `IsTerminal` trait to determine if a descriptor or handle is a terminalJosh Triplett-0/+2
The UNIX and WASI implementations use `isatty`. The Windows implementation uses the same logic the `atty` crate uses, including the hack needed to detect msys terminals. Implement this trait for `File` and for `Stdin`/`Stdout`/`Stderr` and their locked counterparts on all platforms. On UNIX and WASI, implement it for `BorrowedFd`/`OwnedFd`. On Windows, implement it for `BorrowedHandle`/`OwnedHandle`. Based on https://github.com/rust-lang/rust/pull/91121 Co-authored-by: Matt Wilkinson <mattwilki17@gmail.com>
2022-10-07Make tests capture the error printed by a Result returnDavid Tolnay-0/+1
2022-09-26replace stabilization placeholdersPietro Albini-1/+1
2022-08-28Stabilize `std::io::read_to_string`Noah Lev-3/+1
2022-08-28Rollup merge of #100520 - jakubdabek:patch-1, r=thomccMatthias Krüger-1/+6
Add mention of `BufReader` in `Read::bytes` docs There is a general paragraph about `BufRead` in the `Read` trait's docs, however using `bytes` without `BufRead` *always* has a large impact, due to reads of size 1. `@rustbot` label +A-docs
2022-08-18Address reviewer commentsNick Cameron-8/+8
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-14Add mention of `BufReader` in `Read::bytes` docsJakub Dąbek-1/+6
2022-08-05non-linux platformsNick Cameron-11/+10
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-08-04std::io: migrate ReadBuf to BorrowBuf/BorrowCursorNick Cameron-40/+43
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-07-26Rollup merge of #99716 - sourcelliu:iomut, r=Mark-SimulacrumMatthias Krüger-4/+4
remove useless mut from examples remove useless mut from examples