about summary refs log tree commit diff
path: root/library/std/src/io
AgeCommit message (Collapse)AuthorLines
2023-04-21Rollup merge of #110633 - scottmcm:more-take, r=thomccDylan DPC-4/+4
More `mem::take` in `library` A bunch of places were using `replace(…, &mut [])`, but that can just be `take`.
2023-04-20More `mem::take` in `library`Scott McMurray-4/+4
A bunch of places were using `replace(…, &mut [])`, but that can just be `take`.
2023-04-20Specialize some `io::Read` and `io::Write` methods for `VecDeque<u8>` and ↵Benoît du Garreau-0/+54
`&[u8]`
2023-04-20Implement `BufRead` for `VecDeque<u8>`Benoît du Garreau-0/+18
2023-04-14Rollup merge of #110244 - kadiwa4:unnecessary_imports, r=JohnTitorMatthias Krüger-1/+0
Remove some unneeded imports / qualified paths Continuation of #105537.
2023-04-12remove some unneeded importsKaDiWa-1/+0
2023-04-10Stabilize IsTerminalJosh Triplett-3/+4
closes: https://github.com/rust-lang/rust/issues/98070
2023-04-06Remove an unnecessary `mut` in `BufWriter::into_parts`.管唯宇-1/+1
`ptr::read` takes `*const T` so `&mut` is not necessary.
2023-03-28Add "Platform-specific behavior" heading and link to changes disclaimerJosh Triplett-0/+5
2023-03-28Document the heuristics IsTerminal uses on WindowsJosh Triplett-0/+4
2023-03-27Rollup merge of #98651 - mattfbacon:master, r=ChrisDentonMatthias Krüger-1/+1
Follow C-RW-VALUE in std::io::Cursor example rustc-dev-guide says to do this: r? ``@steveklabnik``
2023-03-23Rollup merge of #106964 - ↵Matthias Krüger-2/+10
workingjubilee:crouching-ioerror-hidden-documentation, r=ChrisDenton Clarify `Error::last_os_error` can be weird Fundamentally, querying the OS for error codes is a process that is deeply subject to the whims of chance and fortune. We can account for OS, but not for every combination of platform APIs. A compiled binary may not recognize new errors introduced years later. We should clarify a few especially odd situations, and what they mean: We can effectively promise nothing... if you ask for Rust to decode errors where none have occurred. This allows removing mention of ErrorKind::Uncategorized. That error variant is hidden deliberately, so we should not explicitly mention it. This fixes #106937. Since you had an opinion also: Does this solution seem acceptable? r? ``@ChrisDenton``
2023-03-21Rollup merge of #108326 - tmiasko:read-buf, r=thomccnils-1/+12
Implement read_buf for a few more types Implement read_buf for TcpStream, Stdin, StdinLock, ChildStdout, ChildStderr (and internally for AnonPipe, Handle, Socket), so that it skips buffer initialization. The other provided methods like read_to_string and read_to_end are implemented in terms of read_buf and so benefit from the optimization as well. This commit also implements read_vectored and is_read_vectored where applicable.
2023-03-17Remove irrelevant docs on error kindsJubilee Young-10/+4
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-06Implement read_buf for a few more typesTomasz Miąsko-1/+12
Implement read_buf for TcpStream, Stdin, StdinLock, ChildStdout, ChildStderr (and internally for AnonPipe, Handle, Socket), so that it skips buffer initialization. The other provided methods like read_to_string and read_to_end are implemented in terms of read_buf and so benefit from the optimization as well. This commit also implements read_vectored and is_read_vectored where applicable.
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-2/+2
2023-02-03Update library/std/src/io/mod.rsMichal Nazarewicz-4/+4
2023-01-31std: add type alias for raw OS errorsjoboet-10/+26
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-21Remove unnecessary `&format!`Nikolai Vazquez-1/+1
These were likely from before the `PartialEq<str>` impl for `&String`.
2023-01-17Rollup merge of #106148 - chenyukang:yukang/fix-105061-unused, r=lcnrDylan DPC-4/+4
Fix unused_parens issue for higher ranked function pointers fixes #105061 r? `@lcnr`
2023-01-16Explain the "no-error" io::Error caseJubilee Young-2/+16
Fundamentally, querying the OS for error codes is a process that is deeply subject to the whims of chance and fortune. We can account for OS, but not for every combination of platform APIs. A compiled binary may not recognize new errors introduced years later. We should clarify a few especially odd situations, and what they mean: We can effectively promise nothing. This allows removing mention of ErrorKind::Uncategorized. That error variant is hidden quite deliberately, so we should not explicitly mention it.
2023-01-14Remove various double spaces in source comments.André Vennberg-2/+2
2023-01-14fix issues in unused lintyukang-4/+4
2023-01-01Document a way to limit read_line lengthKornel-2/+3
2023-01-01Document read_line gotchaKornel-2/+5
2022-12-30Replace libstd, libcore, liballoc in line comments.jonathanCogan-4/+4
2022-11-14std: move `ReentrantMutex` to `sync`joboet-2/+1
2022-10-29Add BorrowedBuf::filled_mutAlex Saveau-0/+7
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-24Fix grammar in docs for std::io::ReadJesse Ruderman-2/+2
2022-10-15Auto merge of #98033 - joshtriplett:is-terminal-fd-handle, r=thomccbors-0/+31
Add `IsTerminal` trait to determine if a descriptor or handle is a terminal The UNIX implementation uses `isatty`. The Windows implementation uses the same logic the `atty` crate uses, including the hack needed to detect msys terminals. Implement this trait for `Stdin`/`Stdout`/`Stderr`/`File` on all platforms. On Unix, 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-15Add `IsTerminal` trait to determine if a descriptor or handle is a terminalJosh Triplett-0/+31
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-14Rollup merge of #103067 - Nilstrieb:tidy-likes-the-alphabet, r=jackh726Matthias Krüger-1/+2
More alphabetical sorting Sort and enforce a few more things. The biggest change here is sorting all target features.
2022-10-14Rollup merge of #102781 - StackOverflowExcept1on:master, r=joshtriplettMatthias Krüger-1/+2
Improved documentation for `std::io::Error`
2022-10-14Add some tidy-alphabeticalnils-1/+2
2022-10-14Tweak grammarJosh Triplett-1/+1
2022-10-13fix small word dupe typosRageking8-1/+1
2022-10-12Rollup merge of #102811 - the8472:bufread-memset, r=m-ou-seDylan DPC-3/+6
Use memset to initialize readbuf The write loop was found to be slow in #102727 The proper fix is in #102760 but this might still help debug builds and code running under miri by using the write_bytes intrinsic instead of writing one byte at a time.
2022-10-10Rollup merge of #102794 - dtolnay:termination, r=thomccDylan DPC-6/+23
Make tests capture the error printed by a Result return An error returned by tests previously would get written directly to stderr, instead of to the capture buffer set up by the test harness. This PR makes it write to the capture buffer so that it can be integrated as part of the test output by build tools such as `buck test`, since being able to read the error message returned by a test is pretty critical to debugging why the test failed. <br> **Before:** ```rust // tests/test.rs #[test] fn test() -> Result<(), &'static str> { println!("STDOUT"); eprintln!("STDERR"); Err("RESULT") } ``` ```console $ cargo build --test test $ target/debug/deps/test-???????????????? -Z unstable-options --format=json { "type": "suite", "event": "started", "test_count": 1 } { "type": "test", "event": "started", "name": "test" } Error: "RESULT" { "type": "test", "name": "test", "event": "failed", "stdout": "STDOUT\nSTDERR\n" } { "type": "suite", "event": "failed", "passed": 0, "failed": 1, "ignored": 0, "measured": 0, "filtered_out": 0, "exec_time": 0.00040313 } ``` **After:** ```console $ target/debug/deps/test-???????????????? -Z unstable-options --format=json { "type": "suite", "event": "started", "test_count": 1 } { "type": "test", "event": "started", "name": "test" } { "type": "test", "name": "test", "event": "failed", "stdout": "STDOUT\nSTDERR\nError: \"RESULT\"" } { "type": "suite", "event": "failed", "passed": 0, "failed": 1, "ignored": 0, "measured": 0, "filtered_out": 0, "exec_time": 0.000261894 } ```
2022-10-08use memset to initialize a readbufThe 8472-3/+6
2022-10-07Make tests capture the error printed by a Result returnDavid Tolnay-6/+23
2022-10-07Improved documentation for `std::io::Error`StackOverflowExcept1on-1/+2
2022-10-06Avoid defensive re-initialization of the BufReader bufferBen Kimock-3/+48
2022-09-26remove cfg(bootstrap)Pietro Albini-1/+0
2022-09-26replace stabilization placeholdersPietro Albini-1/+1
2022-09-07stdio: Document no support for writing to non-blocking stdio/stderrUsama Arif-0/+3
Printing to stdio/stderr that have been opened with non-blocking (O_NONBLOCK in linux) can result in an error, which is not handled by std::io module causing a panic. Signed-off-by: Usama Arif <usama.arif@bytedance.com>
2022-09-05std: fix cleanup for uninitialized stdout (#101375)joboet-8/+17