about summary refs log tree commit diff
path: root/library/std/src/io
AgeCommit message (Collapse)AuthorLines
2021-08-24io::Error: alphabeticise the match in as_str()Ian Jackson-5/+6
There was no rationale for the previous ordering. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-1/+1
same search
2021-08-09Auto merge of #87820 - elichai:patch-2, r=kennytmbors-14/+14
Replace read_to_string with read_line in Stdin example The current example results in infinitely reading from stdin, which can confuse newcomers trying to read from stdin. (`@razmag` encountered this while learning the language from the docs)
2021-08-08Auto merge of #86744 - ijackson:sink-default, r=dtolnaybors-0/+2
impl Default, Copy, Clone for std::io::Sink and Empty The omission of `Sink: Default` is causing me a slight inconvenience in a test harness. There seems little reason for this and `Empty` not to be `Clone` and `Copy` too. I have made all three of these insta-stable, because: AIUI `Copy` can only be derived, and I was not able to find any examples of how to unstably derive it. I think it is probably not possible. I hunted through the git history for precedent and found > 79b8ad84c84481a43704213cd0948d2ba0ea63b4 > Implement `Copy` for `IoSlice` > https://github.com/rust-lang/rust/pull/69403 which was also insta-stable.
2021-08-06Replace read_to_string with read_line in Stdin exampleElichai Turkel-14/+14
2021-07-30Consistent spelling of "adapter" in the standard libraryFrank Steffahn-12/+12
Change all occurrences of "(A|a)daptor" to "(A|a)dapter".
2021-07-30Auto merge of #87445 - amalik18:issue-83584-fix, r=kennytmbors-2/+2
Fix may not to appropriate might not or must not I went through and changed occurrences of `may not` to be more explicit with `might not` and `must not`.
2021-07-29Rename feature gate bufwriter_into_parts from bufwriter_into_raw_partsIan Jackson-10/+10
As requested https://github.com/rust-lang/rust/pull/85901#pullrequestreview-698404772 Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-29BufWriter: rename `into_parts` from `into_raw_parts`Ian Jackson-6/+6
I looked in stdlib and as @BurntSushi thought, `raw` is generally used for raw pointers, or other hazardous kinds of thing. stdlib does not have `into_parts` apart from the one I added to `IntoInnerError`. I did an ad-hoc search of the rustdocs for my current game project Otter, which includes quite a large number of dependencies. `into_parts` seems heavily used for things quite like this. So change this name. Suggested-by: Andrew Gallant <jamslam@gmail.com> Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-29BufWriter: actually export WriterPanicked errorIan Jackson-0/+4
I didn't notice the submodule, which means I failed to re-export this to make it actually-public. Reported-by: Andrew Gallant <jamslam@gmail.com> Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-29Fix may not to appropriate might not or must notAli Malik-2/+2
2021-07-24Rollup merge of #87175 - inquisitivecrystal:inner-error, r=kennytmYuki Okushi-4/+2
Stabilize `into_parts()` and `into_error()` This stabilizes `IntoInnerError`'s `into_parts()` and `into_error()` methods, currently gated behind the `io_into_inner_error_parts` feature. The FCP has [already completed.](https://github.com/rust-lang/rust/issues/79704#issuecomment-880652967) Closes #79704.
2021-07-22Remove Option from BufWriterAlex Macleod-10/+14
Fixes #72925
2021-07-21Auto merge of #86847 - tlyu:stdin-forwarders, r=joshtriplettbors-1/+44
add `Stdin::lines`, `Stdin::split` forwarder methods Add forwarder methods `Stdin::lines` and `Stdin::split`, which consume and lock a `Stdin` handle, and forward on to the corresponding `BufRead` methods. This should make it easier for beginners to use those iterator constructors without explicitly dealing with locks or lifetimes. Replaces #86412. ~~Based on #86846 to get the tracking issue number for the `stdio_locked` feature.~~ Rebased after merge, so it's only one commit now. r? `@joshtriplett` `@rustbot` label +A-io +C-enhancement +D-newcomer-roadblock +T-libs-api
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-15Stabilize `into_parts()` and `into_error()`inquisitivecrystal-4/+2
2021-07-15Added diagnostic items to structs and traits for ClippyxFrednet-0/+2
2021-07-12add Stdin::lines, Stdin::split forwarder methodsTaylor Yu-1/+44
Add forwarder methods `Stdin::lines` and `Stdin::split`, which consume and lock a `Stdin` handle, and forward on to the corresponding `BufRead` methods. This should make it easier for beginners to use those iterator constructors without explicitly dealing with locks or lifetimes.
2021-07-13Rollup merge of #86846 - tlyu:stdio-locked-tracking, r=joshtriplettYuki Okushi-7/+7
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-13Rollup merge of #86811 - soerenmeier:remove_remaining, r=yaahcYuki Okushi-26/+0
Remove unstable `io::Cursor::remaining` Adding `io::Cursor::remaining` in #86037 caused a conflict with the implementation of `bytes::Buf` for `io::Cursor`, leading to an error in nightly, see https://github.com/rust-lang/rust/issues/86369#issuecomment-867723485. This fixes the error by temporarily removing the `remaining` function. r? `@yaahc`
2021-07-06Rollup merge of #86794 - inquisitivecrystal:seek-rewind, r=m-ou-seYuki Okushi-2/+5
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-7/+7
2021-07-03Auto merge of #86799 - tlyu:stdio-locked, r=joshtriplettbors-1/+337
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-03Auto merge of #79965 - ijackson:moreerrnos, r=joshtriplettbors-21/+139
More ErrorKinds for common errnos From the commit message of the main commit here (as revised): ``` There are a number of IO error situations which it would be very useful for Rust code to be able to recognise without having to resort to OS-specific code. Taking some Unix examples, `ENOTEMPTY` and `EXDEV` have obvious recovery strategies. Recently I was surprised to discover that `ENOSPC` came out as `ErrorKind::Other`. Since I am familiar with Unix I reviwed the list of errno values in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html Here, I add those that most clearly seem to be needed. `@CraftSpider` provided information about Windows, and references, which I have tried to take into account. This has to be insta-stable because we can't sensibly have a different set of ErrorKinds depending on a std feature flag. I have *not* added these to the mapping tables for any operating systems other than Unix and Windows. I hope that it is OK to add them now for Unix and Windows now, and maybe add them to other OS's mapping tables as and when someone on that OS is able to consider the situation. I adopted the general principle that it was usually a bad idea to map two distinct error values to the same Rust error code. I notice that this principle is already violated in the case of `EACCES` and `EPERM`, which both map to `PermissionDenied`. I think this was probably a mistake but it would be quite hard to change now, so I don't propose to do anything about that. However, for Windows, there are sometimes different error codes for identical situations. Eg there are WSA* versions of some error codes as well as ERROR_* ones. Also Windows seems to have a great many more erorr codes. I don't know precisely what best practice would be for Windows. ``` <strike> ``` Errno values I wasn't sure about so *haven't* included: EMFILE ENFILE ENOBUFS ENOLCK: These are all fairly Unix-specific resource exhaustion situations. In practice it seemed not very likely to me that anyone would want to handle these differently to `Other`. ENOMEM ERANGE EDOM EOVERFLOW Normally these don't get exposed to the Rust callers I hope. They don't tend to come out of filesystem APIs. EILSEQ Hopefully Rust libraries open files in binary mode and do the converstion in Rust. So Rust code ought not to be exposed to EILSEQ. EIO The range of things that could cause this is troublesome. I found it difficult to describe. I do think it would be useful to add this at some point, because EIO on a filesystem operation is much more serious than most other errors. ENETDOWN I wasn't sure if this was useful or, indeed, if any modern systems use it. ENOEXEC It is not clear to me how a Rust program could respond to this. It seems rather niche. EPROTO ENETRESET ENODATA ENOMSG ENOPROTOOPT ENOSR ENOSTR ETIME ENOTRECOVERABLE EOWNERDEAD EBADMSG EPROTONOSUPPORT EPROTOTYPE EIDRM These are network or STREAMS related errors which I have never in my own Unix programming found the need to do anything with. I think someone who understands these better should be the one to try to find good Rust names and descriptions for them. ENOTTY ENXIO ENODEV EOPNOTSUPP ESRCH EALREADY ECANCELED ECHILD EINPROGRESS These are very hard to get unless you're already doing something very Unix-specific, in which case the raw_os_error interface is probably more suitable than relying on the Rust ErrorKind mapping. EFAULT EBADF These would seem to be the result of application UB. ``` </strike> <i>(omitted errnos are discussed below, especially in https://github.com/rust-lang/rust/pull/79965#issuecomment-810468334)
2021-07-02stdio_locked: updates based on feedbackTaylor Yu-74/+14
Rename methods to `into_locked`. Remove type aliases for owned locks.
2021-07-02Remove unstable `Cursor::remaining`Sören Meier-26/+0
2021-07-02Auto merge of #85746 - m-ou-se:io-error-other, r=joshtriplettbors-8/+23
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-1/+397
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/+5
2021-06-30impl Default, Copy, Clone for std::io::Sink and EmptyIan Jackson-0/+2
The omission of Sink: Default is causing me a slight inconvenience in a test harness. There seems little reason for this and Empty not to be Clone and Copy too. I have made all three of these insta-stable, because: AIUI Copycan only be derived, and I was not able to find any examples of how to unstably derive it. I think it is probably not possible. I hunted through the git history for precedent and found 79b8ad84c84481a43704213cd0948d2ba0ea63b4 Implement `Copy` for `IoSlice` https://github.com/rust-lang/rust/pull/69403 which was also insta-stable. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-25Restore original ordering of `ErrorKind::Other`.Mara Bos-8/+9
2021-06-24Use `#[non_exhaustive]` where appropriateJacob Pratt-8/+6
Due to the std/alloc split, it is not possible to make `alloc::collections::TryReserveError::AllocError` non-exhaustive without having an unstable, doc-hidden method to construct (which negates the benefits from `#[non_exhaustive]`.
2021-06-22Rollup merge of #86037 - soerenmeier:cursor_remaining, r=yaahcYuki Okushi-4/+85
Add `io::Cursor::{remaining, remaining_slice, is_empty}` Tracking issue: #86369 I came across an inconvenience when answering the following [Stack Overflow](https://stackoverflow.com/questions/67831170) question. To get the remaining slice you have to call `buff.fill_buf().unwrap()`. Which in my opinion doesn't really tell you what is returned (in the context of Cursor). To improve readability and convenience when using Cursor i propose adding the method `remaining`. The next thing i found inconvenient (unnecessary long) was detecting if the cursor reached the end. There are a few ways this can be achieved right now: - `buff.fill_buf().unwrap().is_empty()` - `buff.position() >= buff.get_ref().len()` - `buff.bytes().next().is_none()` Which all seem a bit unintuitive, hidden in trait documentations or just a bit long for such a simple task. Therefor i propose another method called `is_empty`, maybe with another name, since this one may leave room for interpretation on what really is empty (the underlying slice, the remaining slice or maybe the position). Since it seemed easier to create this PR instead of an RFC i did that, if an RFC is wanted, i can close this PR and write an RFC first.
2021-06-20ErrorKind: Add missing full stopsIan Jackson-3/+3
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-20ErrorKind::FilesystemLoop: Generalise dscriptionIan Jackson-3/+4
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18Auto merge of #85815 - YuhanLiin:buf-read-data-left, r=m-ou-sebors-0/+41
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-18ErrorKind::NotSeekable: Fix reference to File::open()Ian Jackson-1/+1
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18ErrorKind: Provide many more ErrorKinds, motivated by Unix errnosIan Jackson-0/+116
Rationale for the mappings etc. is extensively discussed in the MR https://github.com/rust-lang/rust/pull/79965 Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18ErrorKind: Reformat the error string tableIan Jackson-21/+22
* Sort alphabetically. * use ErrorKind::*; Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-17Update tracking issueYuhanLiin-1/+1
2021-06-17Rollup merge of #86202 - a1phyr:spec_io_bytes_size_hint, r=m-ou-seMara Bos-3/+96
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-17Rollup merge of #85802 - Thomasdezeeuw:ioslice-advance, r=m-ou-seYuki Okushi-30/+81
Rename IoSlice(Mut)::advance to advance_slice and add IoSlice(Mut)::advance Also changes the signature of `advance_slice` to accept a `&mut &mut [IoSlice]`, not returning anything. This will better match the `IoSlice::advance` function. Updates https://github.com/rust-lang/rust/issues/62726.
2021-06-17Fix typos in code examples.Mara Bos-2/+2
2021-06-17rename `remaining` to `remaining_slice` and add a new `remaining`Sören Meier-8/+34
2021-06-16Update tracking issueSören Meier-2/+2
2021-06-15Rename ErrorKind::Unknown to Uncategorized.Mara Bos-7/+7
2021-06-15Redefine `ErrorKind::Other` and stop using it in std.Mara Bos-11/+25
2021-06-10Specialize `io::Bytes::size_hint` for more typesBenoît du Garreau-3/+96
2021-06-07Forwarding implementation for Seek trait's stream_position methodmyshylin-0/+10