summary refs log tree commit diff
path: root/library/std/src/io/mod.rs
AgeCommit message (Collapse)AuthorLines
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
2021-01-31Add back lower_bound as memeberXavientois-0/+2
2021-01-31Add default keyword for specializationXavientois-5/+5
2021-01-31Fix incorrect tokenXavientois-1/+1
2021-01-31Move default to trait definitionXavientois-6/+4
2021-01-31Add missing genericXavientois-1/+1
2021-01-31Use helper trait to follow min_specialization rulesXavientois-4/+24
2021-01-31Fix implementation to specializeXavientois-1/+1
2021-01-31Implement size_hint for BufReaderXavientois-2/+21
2021-01-24Stabilize `Seek::stream_position` & change feature of `Seek::stream_len`Lukas Kalbertodt-4/+3
2021-01-17Add benchmark and fast path for BufReader::read_exactBen Kimock-17/+21
2021-01-14Rollup merge of #80895 - sfackler:read-to-end-ub, r=m-ou-seMara Bos-12/+10
Fix handling of malicious Readers in read_to_end A malicious `Read` impl could return overly large values from `read`, which would result in the guard's drop impl setting the buffer's length to greater than its capacity! ~~To fix this, the drop impl now uses the safe `truncate` function instead of `set_len` which ensures that this will not happen. The result of calling the function will be nonsensical, but that's fine given the contract violation of the `Read` impl.~~ ~~The `Guard` type is also used by `append_to_string` which does not pass untrusted values into the length field, so I've copied the guard type into each function and only modified the one used by `read_to_end`. We could just keep a single one and modify it, but it seems a bit cleaner to keep the guard code close to the functions and related specifically to them.~~ To fix this, we now assert that the returned length is not larger than the buffer passed to the method. For reference, this bug has been present for ~2.5 years since 1.20: https://github.com/rust-lang/rust/commit/ecbb896b9eb2acadefde57be493e4298c1aa04a3. Closes #80894.
2021-01-14Rollup merge of #80217 - camelid:io-read_to_string, r=m-ou-seMara Bos-0/+48
Add a `std::io::read_to_string` function I recognize that you're usually supposed to open an issue first, but the implementation is very small so it's okay if this is closed and it was 'wasted work' :) ----- The equivalent of `std::fs::read_to_string`, but generalized to all `Read` impls. As the documentation on `std::io::read_to_string` says, the advantage of this function is that it means you don't have to create a variable first and it provides more type safety since you can only get the buffer out if there were no errors. If you use `Read::read_to_string`, you have to remember to check whether the read succeeded because otherwise your buffer will be empty. It's friendlier to newcomers and better in most cases to use an explicit return value instead of an out parameter.
2021-01-11Add docs on performanceCamelid-0/+13
2021-01-11clarify docs a bitSteven Fackler-4/+3
2021-01-11make check a bit more clearSteven Fackler-2/+3
2021-01-11clean up control flowSteven Fackler-11/+2
2021-01-11Fix handling of malicious Readers in read_to_endSteven Fackler-1/+8
2020-12-31Remove many unnecessary manual link resolves from libraryCamelid-2/+0
Now that #76934 has merged, we can remove a lot of these! E.g, this is no longer necessary: [`Vec<T>`]: Vec
2020-12-30Add error docsCamelid-1/+8
2020-12-30Add description independent of `Read::read_to_string`Camelid-5/+6
2020-12-19Add a `std::io::read_to_string` functionCamelid-0/+27
The equivalent of `std::fs::read_to_string`, but generalized to all `Read` impls. As the documentation on `std::io::read_to_string` says, the advantage of this function is that it means you don't have to create a variable first and it provides more type safety since you can only get the buffer out if there were no errors. If you use `Read::read_to_string`, you have to remember to check whether the read succeeded because otherwise your buffer will be empty. It's friendlier to newcomers and better in most cases to use an explicit return value instead of an out parameter.
2020-11-17Fix typo in `std::io::Write` docsWilliam Chargin-2/+2
These referred to a “`Write`er”—extra *e*. Presumably a copy-paste holdover from “`Read`er”. Test Plan: Running ``git grep '`\?[Ww]rite`\?er'`` no longer finds any results. wchargin-branch: io-write-docs