about summary refs log tree commit diff
path: root/library/std/src/io/stdio.rs
AgeCommit message (Collapse)AuthorLines
2024-12-01add isatty alias for is_terminalcod10129-0/+1
2024-10-10More clearly document Stdin::read_lineTim (Theemathas) Chirananthavat-1/+6
These are common pitfalls for beginners, so I think it's worth making the subtleties more visible.
2024-10-02Add `get_line` confusable to `Stdin::read_line()`Jaken Herman-0/+1
Add tests for addition of `#[rustc_confusables("get_line")]`
2024-07-29Reformat `use` declarations.Nicholas Nethercote-2/+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-26Fix doc nitsJohn Arundel-1/+1
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-06-05Update description of the `IsTerminal` exampleChris Denton-3/+2
2024-05-19Add example to IsTerminal::is_terminalMartijn-0/+34
2024-04-11Rollup merge of #122882 - Zoxc:panic-output-panic, r=AmanieuMatthias Krüger-2/+22
Avoid a panic in `set_output_capture` in the default panic handler This avoid a panic in the default panic handler by not using `set_output_capture` as `OUTPUT_CAPTURE.with` may panic once `OUTPUT_CAPTURE` is dropped. A new non-panicking `try_set_output_capture` variant of `set_output_capture` is added for use in the default panic handler.
2024-04-10Auto merge of #122393 - a1phyr:specialize_read_buf_exact, r=joboetbors-0/+10
Specialize many implementations of `Read::read_buf_exact` This makes all implementations of `Read` that have a specialized `read_exact` implementation also have one for `read_buf_exact`.
2024-03-22Avoid a panic in `set_output_capture` in the default panic handlerJohn Kåre Alsaker-2/+22
2024-03-19branch 1.78: replace-version-placeholderMark Rousskov-1/+1
2024-03-12Specialize many implementations of `Read::read_buf_exact`Benoît du Garreau-0/+10
2024-03-09Rollup merge of #99153 - Dajamante:issue/95622, r=dtolnayGuillaume Boisseau-0/+26
Add Read Impl for &Stdin r? `@oli-obk` fixes #95622
2024-03-03Fix quadratic behavior of repeated vectored writesJan Verbeek-4/+11
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-26Fill in Read::read_buf for &StdinDavid Tolnay-0/+3
2024-02-26Fix stable feature name and stabilization version of Read for &StdinDavid Tolnay-1/+1
2024-02-23std: make `ReentrantLock` publicjoboet-10/+35
2024-01-17specialize `Bytes` on `StdinLock<'_>` by using the underlying `BufReader`Aldan Tanneo-1/+10
2023-10-05Add more diagnostic items for clippyJason Newcomb-0/+2
2023-04-28replace version placeholdersPietro Albini-3/+3
2023-04-10Stabilize IsTerminalJosh Triplett-2/+3
closes: https://github.com/rust-lang/rust/issues/98070
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-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.
2022-11-14std: move `ReentrantMutex` to `sync`joboet-2/+1
2022-10-15Add `IsTerminal` trait to determine if a descriptor or handle is a terminalJosh Triplett-0/+29
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-6/+22
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
2022-09-04Auto merge of #100576 - joboet:movable_const_remutex, r=Mark-Simulacrumbors-25/+16
Make `ReentrantMutex` movable and `const` As `MovableMutex` is now `const`, it can be used to simplify the implementation and interface of the internal reentrant mutex type. Consequently, the standard error stream does not need to be wrapped in `OnceLock` and `OnceLock::get_or_init_pin()` can be removed.
2022-09-03std: make `ReentrantMutex` movable and `const`; simplify `Stdout` initializationjoboet-25/+16
2022-09-01Update outdated comment about output capturing in print_to.Mara Bos-4/+4
2022-07-23Remove `mut`Phosra-1/+1
2022-07-11Add Read Impl for &StdinAïssata-0/+23
2022-06-16Move/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock`Maybe Waffle-5/+4
2022-04-06Bump stabilization of stdin_forwarders to 1.62.0.Mara Bos-1/+1
2022-03-21Stabilize Stdin::lines.Mara Bos-2/+1
2022-03-19Rollup merge of #93263 - sunfishcode:sunfishcode/detatched-console-handle, ↵Dylan DPC-9/+70
r=dtolnay Consistently present absent stdio handles on Windows as NULL handles. This addresses #90964 by making the std API consistent about presenting absent stdio handles on Windows as NULL handles. Stdio handles may be absent due to `#![windows_subsystem = "windows"]`, due to the console being detached, or due to a child process having been launched from a parent where stdio handles are absent. Specifically, this fixes the case of child processes of parents with absent stdio, which previously ended up with `stdin().as_raw_handle()` returning `INVALID_HANDLE_VALUE`, which was surprising, and which overlapped with an unrelated valid handle value. With this patch, `stdin().as_raw_handle()` now returns null in these situation, which is consistent with what it does in the parent process. And, document this in the "Windows Portability Considerations" sections of the relevant documentation.
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-4/+4
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-03-04Consistently present absent stdio handles on Windows as NULL handles.Dan Gohman-9/+70
This addresses #90964 by making the std API consistent about presenting absent stdio handles on Windows as NULL handles. Stdio handles may be absent due to `#![windows_subsystem = "windows"]`, due to the console being detached, or due to a child process having been launched from a parent where stdio handles are absent. Specifically, this fixes the case of child processes of parents with absent stdio, which previously ended up with `stdin().as_raw_handle()` returning `INVALID_HANDLE_VALUE`, which was surprising, and which overlapped with an unrelated valid handle value. With this patch, `stdin().as_raw_handle()` now returns null in these situation, which is consistent with what it does in the parent process. And, document this in the "Windows Portability Considerations" sections of the relevant documentation.
2022-02-13Make default stdio lock() return 'static handlesMark Rousskov-223/+15
This also deletes the unstable API surface area previously added to expose this functionality on new methods rather than built into the current set.
2022-01-20delete `Stdin::split` forwarderTaylor Yu-24/+1
2021-12-14Fix a bunch of typosFrank Steffahn-1/+1
2021-11-02read_bufDrMeepster-15/+1
2021-10-31Rollup merge of #90430 - jkugelman:must-use-std-a-through-n, r=joshtriplettMatthias Krüger-0/+3
Add #[must_use] to remaining std functions (A-N) I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is half of the remaining items from the `std` crate, from A-N. I added these functions myself. Clippy predictably ignored the `mut` ones, but I don't know why the rest weren't flagged. Check them closely, please? Maybe I overlooked good reasons. ```rust std::backtrace::Backtrace const fn disabled() -> Backtrace; std::backtrace::Backtrace<'a> fn frames(&'a self) -> &'a [BacktraceFrame]; std::collections::hash_map::RawOccupiedEntryMut<'a, K, V> fn key_mut(&mut self) -> &mut K; std::collections::hash_map::RawOccupiedEntryMut<'a, K, V> fn get_mut(&mut self) -> &mut V; std::collections::hash_map::RawOccupiedEntryMut<'a, K, V> fn get_key_value(&mut self) -> (&K, &V); std::collections::hash_map::RawOccupiedEntryMut<'a, K, V> fn get_key_value_mut(&mut self) -> (&mut K, &mut V); std::env fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString>; std::env fn split_paths<T: AsRef<OsStr> + ?Sized>(unparsed: &T) -> SplitPaths<'_>; std::io::Error fn get_mut(&mut self) -> Option<&mut (dyn error::Error + Send + Sync + 'static)>; ``` Parent issue: #89692 r? `@joshtriplett`
2021-10-30Add #[must_use] to remaining std functions (A-N)John Kugelman-0/+3
2021-10-12Add #[must_use] to expensive computationsJohn Kugelman-0/+1
The unifying theme for this commit is weak, admittedly. I put together a list of "expensive" functions when I originally proposed this whole effort, but nobody's cared about that criterion. Still, it's a decent way to bite off a not-too-big chunk of work. Given the grab bag nature of this commit, the messages I used vary quite a bit.
2021-10-10Add #[must_use] to conversions that move selfJohn Kugelman-0/+1
2021-10-08Add #[must_use] to stdin/stdout/stderr locksJohn Kugelman-0/+3
2021-08-06Replace read_to_string with read_line in Stdin exampleElichai Turkel-14/+14