summary refs log tree commit diff
path: root/library/std/src/io/mod.rs
AgeCommit message (Collapse)AuthorLines
2021-07-18Rollup merge of #87170 - xFrednet:clippy-5393-add-diagnostic-items, ↵Yuki Okushi-0/+2
r=Manishearth,oli-obk Add diagnostic items for Clippy This adds a bunch of diagnostic items to `std`/`core`/`alloc` functions, structs and traits used in Clippy. The actual refactorings in Clippy to use these items will be done in a different PR in Clippy after the next sync. This PR doesn't include all paths Clippy uses, I've only gone through the first 85 lines of Clippy's [`paths.rs`](https://github.com/rust-lang/rust-clippy/blob/ecf85f4bdc319f9d9d853d1fff68a8a25e64c7a8/clippy_utils/src/paths.rs) (after rust-lang/rust-clippy#7466) to get some feedback early on. I've also decided against adding diagnostic items to methods, as it would be nicer and more scalable to access them in a nicer fashion, like adding a `is_diagnostic_assoc_item(did, sym::Iterator, sym::map)` function or something similar (Suggested by `@camsteffen` [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/Diagnostic.20Item.20Naming.20Convention.3F/near/225024603)) There seems to be some different naming conventions when it comes to diagnostic items, some use UpperCamelCase (`BinaryHeap`) and some snake_case (`hashmap_type`). This PR uses UpperCamelCase for structs and traits and snake_case with the module name as a prefix for functions. Any feedback on is this welcome. cc: rust-lang/rust-clippy#5393 r? `@Manishearth`
2021-07-15Added diagnostic items to structs and traits for ClippyxFrednet-0/+2
2021-07-13Rollup merge of #86846 - tlyu:stdio-locked-tracking, r=joshtriplettYuki Okushi-1/+1
stdio_locked: add tracking issue Add the tracking issue number #86845 to the stability attributes for the implementation in #86799. r? `@joshtriplett` `@rustbot` label +A-io +C-cleanup +T-libs-api
2021-07-06Rollup merge of #86794 - inquisitivecrystal:seek-rewind, r=m-ou-seYuki Okushi-2/+1
Stabilize `Seek::rewind()` This stabilizes `Seek::rewind`. It seemed to fit into one of the existing tests, so I extended that test rather than adding a new one. Closes #85149.
2021-07-04Add missing code example for Write::write_vectoredGuillaume Gomez-0/+21
2021-07-03stdio_locked: add tracking issueTaylor Yu-1/+1
2021-07-03Auto merge of #86799 - tlyu:stdio-locked, r=joshtriplettbors-0/+2
add owned locked stdio handles Add stderr_locked, stdin_locked, and stdout_locked free functions to obtain owned locked stdio handles in a single step. Also add into_lock methods to consume a stdio handle and return an owned lock. These methods will make it easier to use locked stdio handles without having to deal with lifetime problems or keeping bindings to the unlocked handles around. Fixes #85383; enables #86412. r? `@joshtriplett` `@rustbot` label +A-io +C-enhancement +D-newcomer-roadblock +T-libs-api
2021-07-02stdio_locked: updates based on feedbackTaylor Yu-2/+0
Rename methods to `into_locked`. Remove type aliases for owned locks.
2021-07-02Auto merge of #85746 - m-ou-se:io-error-other, r=joshtriplettbors-1/+1
Redefine `ErrorKind::Other` and stop using it in std. This implements the idea I shared yesterday in the libs meeting when we were discussing how to handle adding new `ErrorKind`s to the standard library: This redefines `Other` to be for *user defined errors only*, and changes all uses of `Other` in the standard library to a `#[doc(hidden)]` and permanently `#[unstable]` `ErrorKind` that users can not match on. This ensures that adding `ErrorKind`s at a later point in time is not a breaking change, since the user couldn't match on these errors anyway. This way, we use the `#[non_exhaustive]` property of the enum in a more effective way. Open questions: - How do we check this change doesn't cause too much breakage? Will a crate run help and be enough? - How do we ensure we don't accidentally start using `Other` again in the standard library? We don't have a `pub(not crate)` or `#[deprecated(in this crate only)]`. cc https://github.com/rust-lang/rust/pull/79965 cc `@rust-lang/libs` `@ijackson` r? `@dtolnay`
2021-07-01add owned locked stdio handlesTaylor Yu-0/+4
Add stderr_locked, stdin_locked, and stdout_locked free functions to obtain owned locked stdio handles in a single step. Also add into_lock methods to consume a stdio handle and return an owned lock. These methods will make it easier to use locked stdio handles without having to deal with lifetime problems or keeping bindings to the unlocked handles around.
2021-07-01Stabilize `Seek::rewind`Aris Merchant-2/+1
2021-06-18Auto merge of #85815 - YuhanLiin:buf-read-data-left, r=m-ou-sebors-0/+31
Add has_data_left() to BufRead This is a continuation of #40747 and also addresses #40745. The problem with the previous PR was that it had "eof" in its method name. This PR uses a more descriptive method name, but I'm open to changing it.
2021-06-17Update tracking issueYuhanLiin-1/+1
2021-06-17Rollup merge of #86202 - a1phyr:spec_io_bytes_size_hint, r=m-ou-seMara Bos-1/+57
Specialize `io::Bytes::size_hint` for more types Improve the result of `<io::Bytes as Iterator>::size_hint` for some readers. I did not manage to specialize `SizeHint` for `io::Cursor` Side question: would it be interesting for `io::Read` to have an optional `size_hint` method ?
2021-06-17Fix typos in code examples.Mara Bos-2/+2
2021-06-15Rename ErrorKind::Unknown to Uncategorized.Mara Bos-1/+1
2021-06-15Redefine `ErrorKind::Other` and stop using it in std.Mara Bos-1/+1
2021-06-10Specialize `io::Bytes::size_hint` for more typesBenoît du Garreau-1/+57
2021-06-05Rename IoSlice(Mut)::advance_slice to advance_slicesThomas de Zeeuw-8/+8
2021-05-29Add has_data_left() to BufReadYuhanLiin-0/+31
2021-05-29Add IoSlice(Mut)::advanceThomas de Zeeuw-2/+54
Advance the internal cursor of a single slice.
2021-05-29Rename IoSlice(Mut)::advance to advance_sliceThomas de Zeeuw-10/+9
To make way for a new IoSlice(Mut)::advance function that advances a single slice. Also changes the signature to accept a `&mut &mut [IoSlice]`, not returning anything. This will better match the future IoSlice::advance function.
2021-05-24remove cfg(bootstrap)Pietro Albini-4/+2
2021-05-23Rollup merge of #85288 - Geal:clarify-std-io-read, r=dtolnayDylan DPC-1/+7
add an example to explain std::io::Read::read returning 0 in some cases I have always found the explanation about `Read::read` returning 0 to indicate EOF but not indefinitely, so here's more info using Linux as example. I can also add example code if necessary
2021-05-20Rollup merge of #85275 - CDirkx:memchr, r=m-ou-seGuillaume Gomez-1/+1
Move `std::memchr` to `sys_common` `std::memchr` is a thin abstraction over the different `memchr` implementations in `sys`, along with documentation and tests. The module is only used internally by `std`, nothing is exported externally. Code like this is exactly what the `sys_common` module is for, so this PR moves it there.
2021-05-18fix typoJorge Ferreira-2/+2
2021-05-14add an example to explain std::io::Read::read returning 0 in some casesGeoffroy Couprie-1/+7
the example focuses on Linux, but that should be enough to explain how the behaviour can change
2021-05-14Move `std::memchr` to `sys_common`Christiaan Dirkx-1/+1
2021-05-10io::Seek::rewind: Set tracking issueIan Jackson-1/+1
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-10Fix typo in docIan Jackson-1/+1
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-05-10io::Seek: Provide rewind()Ian Jackson-0/+35
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-10io::Seek: Mention that seeking can fail due to buffer flush failIan Jackson-0/+2
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-04-22Rework `at_exit` to `cleanup`Christiaan Dirkx-0/+4
2021-04-02Auto merge of #80965 - camelid:rename-doc-spotlight, r=jyn514bors-2/+4
Rename `#[doc(spotlight)]` to `#[doc(notable_trait)]` Fixes #80936. "spotlight" is not a very specific or self-explaining name. Additionally, the dialog that it triggers is called "Notable traits". So, "notable trait" is a better name. * Rename `#[doc(spotlight)]` to `#[doc(notable_trait)]` * Rename `#![feature(doc_spotlight)]` to `#![feature(doc_notable_trait)]` * Update documentation * Improve documentation r? `@Manishearth`
2021-03-27Derive Debug for io::Chain instead of manually implementing it.Mara Bos-7/+1
The manual implementation has the same bounds, so I don't think there's any reason for a manual implementation. The names used in the derive implementation are even nicer (`first`/`second`) than the manual implementation (`t`/`u`), and include the `done_first` field too.
2021-03-24Rollup merge of #83353 - m-ou-se:io-error-avoid-alloc, r=nagisaDylan DPC-5/+11
Add internal io::Error::new_const to avoid allocations. This makes it possible to have a io::Error containing a message with zero allocations, and uses that everywhere to avoid the *three* allocations involved in `io::Error::new(kind, "message")`. The function signature isn't perfect, because it needs a reference to the `&str`. So for now, this is just a `pub(crate)` function. Later, we'll be able to use `fn new_const<MSG: &'static str>(kind: ErrorKind)` to make that a bit better. (Then we'll also be able to use some ZST trickery if that would result in more efficient code.) See https://github.com/rust-lang/rust/issues/83352
2021-03-21Use io::Error::new_const everywhere to avoid allocations.Mara Bos-5/+11
2021-03-18Clarify docs for Read::read's return valueJannis Harder-2/+7
2021-03-15Rename `#[doc(spotlight)]` to `#[doc(notable_trait)]`Camelid-2/+4
"spotlight" is not a very specific or self-explaining name. Additionally, the dialog that it triggers is called "Notable traits". So, "notable trait" is a better name. * Rename `#[doc(spotlight)]` to `#[doc(notable_trait)]` * Rename `#![feature(doc_spotlight)]` to `#![feature(doc_notable_trait)]` * Update documentation * Improve documentation
2021-03-05Rollup merge of #81136 - Xavientois:io_reader_size_hint, r=cramertjMara-0/+37
Improved IO Bytes Size Hint After trying to implement better `size_hint()` return values for `File` in [this PR](https://github.com/rust-lang/rust/pull/81044) and changing to implementing it for `BufReader` in [this PR](https://github.com/rust-lang/rust/pull/81052), I have arrived at this implementation that provides tighter bounds for the `Bytes` iterator of various readers including `BufReader`, `Empty`, and `Chain`. Unfortunately, for `BufReader`, the size_hint only improves after calling `fill_buffer` due to it using the contents of the buffer for the hint. Nevertheless, the the tighter bounds should result in better pre-allocation of space to handle the contents of the `Bytes` iterator. Closes #81052
2021-02-25Convert primitives to use intra-doc linksJoshua Nelson-2/+1
2021-01-31Fix formatting on modXavientois-2/+1
2021-01-31Implement SizeHint trait for BufReader, Emtpy, and ChainXavientois-6/+14
2021-01-31Use fully qualified syntax to avoid dynXavientois-1/+1
2021-01-31Remove unnecessary default keywordXavientois-4/+6
2021-01-31Remove stable annotationXavientois-3/+0
2021-01-31Fix formattingXavientois-10/+2
2021-01-31Add dyn for SizeHint castXavientois-1/+1
2021-01-31Remove exposing private traitXavientois-2/+2
2021-01-31Fix semicolonXavientois-1/+1