about summary refs log tree commit diff
path: root/src/libstd/io
AgeCommit message (Collapse)AuthorLines
2014-12-07auto merge of #19407 : frewsxcv/rust/rm-reexports, r=cmrbors-25/+35
In regards to: https://github.com/rust-lang/rust/issues/19253#issuecomment-64836729 This commit: * Changes the #deriving code so that it generates code that utilizes fewer reexports (in particur Option::\*, Result::\*, and Ordering::\*), which is necessary to remove those reexports in the future * Changes other areas of the codebase so that fewer reexports are utilized
2014-12-06auto merge of #19431 : erickt/rust/buf-writer-error, r=alexcrichtonbors-17/+27
Previously, `BufWriter::write` would just return an `std::io::OtherIoError` if someone attempted to write past the end of the wrapped buffer. This pull request changes the error to support partial writes and return a `std::io::ShortWrite`, or an `io::io::EndOfFile` if it's been fully exhausted. I've also optimized away a bounds check inside `BufWriter::write`, which should help shave off some nanoseconds in an inner loops.
2014-12-05Utilize fewer reexportsCorey Farwell-25/+35
In regards to: https://github.com/rust-lang/rust/issues/19253#issuecomment-64836729 This commit: * Changes the #deriving code so that it generates code that utilizes fewer reexports (in particur Option::* and Result::*), which is necessary to remove those reexports in the future * Changes other areas of the codebase so that fewer reexports are utilized
2014-12-05rollup merge of #19416: sfackler/global-stdinCorey Richardson-24/+136
io::stdin returns a new `BufferedReader` each time it's called, which results in some very confusing behavior with disappearing output. It now returns a `StdinReader`, which wraps a global singleton `Arc<Mutex<BufferedReader<StdReader>>`. `Reader` is implemented directly on `StdinReader`. However, `Buffer` is not, as the `fill_buf` method is fundamentaly un-thread safe. A `lock` method is defined on `StdinReader` which returns a smart pointer wrapping the underlying `BufferedReader` while guaranteeing mutual exclusion. Code that treats the return value of io::stdin as implementing `Buffer` will break. Add a call to `lock`: ```rust io::stdin().read_line(); // => io::stdin().lock().read_line(); ``` Closes #14434 [breaking-change]
2014-12-05rollup merge of #19364: steveklabnik/doc_buffered_readerCorey Richardson-3/+3
We don't need this &mut, and vec could use []s
2014-12-05std: change BufWriter to return ShortWrite/EndOfFileErick Tryzelaar-17/+27
2014-12-05auto merge of #19303 : nodakai/rust/libsyntax-reject-dirs, r=alexcrichtonbors-9/+23
On *BSD systems, we can `open(2)` a directory and directly `read(2)` from it due to an old tradition. We should avoid doing so by explicitly calling `fstat(2)` to check the type of the opened file. Opening a directory as a module file can't always be avoided. Even when there's no "path" attribute trick involved, there can always be a *directory* named `my_module.rs`. Incidentally, remove unnecessary mutability of `&self` from `io::fs::File::stat()`.
2014-12-04auto merge of #18980 : erickt/rust/reader, r=ericktbors-6/+78
This continues the work @thestinger started in #18885 (which hasn't landed yet, so wait for that to land before landing this one). Instead of adding more methods to `BufReader`, this just allows a `&[u8]` to be used directly as a `Reader`. It also adds an impl of `Writer` for `&mut [u8]`.
2014-12-03Back io::stdin with a global singleton BufferedReaderSteven Fackler-24/+136
io::stdin returns a new `BufferedReader` each time it's called, which results in some very confusing behavior with disappearing output. It now returns a `StdinReader`, which wraps a global singleton `Arc<Mutex<BufferedReader<StdReader>>`. `Reader` is implemented directly on `StdinReader`. However, `Buffer` is not, as the `fill_buf` method is fundamentaly un-thread safe. A `lock` method is defined on `StdinReader` which returns a smart pointer wrapping the underlying `BufferedReader` while guaranteeing mutual exclusion. Code that treats the return value of io::stdin as implementing `Buffer` will break. Add a call to `lock`: ```rust io::stdin().lines() // => io::stdin().lock().lines() ``` Closes #14434 [breaking-change]
2014-12-04libstd: explicitly disallow io::fs::File to open a directory.NODA, Kai-8/+22
On *BSD systems, we can open(2) a directory and directly read(2) from it due to an old tradition. We should avoid doing so by explicitly calling fstat(2) to check the type of the opened file. Opening a directory as a module file can't always be avoided. Even when there's no "path" attribute trick involved, there can always be a *directory* named "my_module.rs". Fix #12460 Signed-off-by: NODA, Kai <nodakai@gmail.com>
2014-12-04libstd: io::fs::File::stat() need not to take &mut self.NODA, Kai-1/+1
The same goes for sys::fs::FileDesc::fstat() on Windows. Signed-off-by: NODA, Kai <nodakai@gmail.com>
2014-12-03Fix falloutJorge Aparicio-1/+1
2014-11-30std: add Reader impl for &[u8]Erick Tryzelaar-6/+66
2014-11-30std: add tests for the Vec<u8> Writer implErick Tryzelaar-0/+12
2014-11-28small doc fixesSteve Klabnik-3/+3
We don't need this &mut, and vec could use []s
2014-11-26rollup merge of #19329: steveklabnik/doc_style_cleanup2Alex Crichton-299/+278
2014-11-26/*! -> //!Steve Klabnik-299/+278
Sister pull request of https://github.com/rust-lang/rust/pull/19288, but for the other style of block doc comment.
2014-11-26rollup merge of #19328: sfackler/buffered-get-mutAlex Crichton-10/+26
This is necessary to e.g. set a timeout on the underlying stream. r? @alexcrichton
2014-11-26rollup merge of #19298: nikomatsakis/unboxed-closure-parse-the-plusAlex Crichton-2/+2
Implements RFC 438. Fixes #19092. This is a [breaking-change]: change types like `&Foo+Send` or `&'a mut Foo+'a` to `&(Foo+Send)` and `&'a mut (Foo+'a)`, respectively. r? @brson
2014-11-26rollup merge of #19273: ogham/rename-file-typesAlex Crichton-22/+21
All of the enum components had a redundant 'Type' specifier: TypeSymlink, TypeDirectory, TypeFile. This change removes them, replacing them with a namespace: FileType::Symlink, FileType::Directory, and FileType::RegularFile. RegularFile is used instead of just File, as File by itself could be mistakenly thought of as referring to the struct. Part of #19253.
2014-11-26auto merge of #19176 : aturon/rust/stab-iter, r=alexcrichtonbors-6/+4
This is an initial pass at stabilizing the `iter` module. The module is fairly large, but is also pretty polished, so most of the stabilization leaves things as they are. Some changes: * Due to the new object safety rules, various traits needs to be split into object-safe traits and extension traits. This includes `Iterator` itself. While splitting up the traits adds some complexity, it will also increase flexbility: once we have automatic impls of `Trait` for trait objects over `Trait`, then things like the iterator adapters will all work with trait objects. * Iterator adapters that use up the entire iterator now take it by value, which makes the semantics more clear and helps catch bugs. Due to the splitting of Iterator, this does not affect trait objects. If the underlying iterator is still desired for some reason, `by_ref` can be used. (Note: this change had no fallout in the Rust distro except for the useless mut lint.) * In general, extension traits new and old are following an [in-progress convention](rust-lang/rfcs#445). As such, they are marked `unstable`. * As usual, anything involving closures is `unstable` pending unboxed closures. * A few of the more esoteric/underdeveloped iterator forms (like `RandomAccessIterator` and `MutableDoubleEndedIterator`, along with various unfolds) are left experimental for now. * The `order` submodule is left `experimental` because it will hopefully be replaced by generalized comparison traits. * "Leaf" iterators (like `Repeat` and `Counter`) are uniformly constructed by free fns at the module level. That's because the types are not otherwise of any significance (if we had `impl Trait`, you wouldn't want to define a type at all). Closes #17701 Due to renamings and splitting of traits, this is a: [breaking-change]
2014-11-26Fixup various places that were doing `&T+'a` and do `&(T+'a)`Niko Matsakis-2/+2
2014-11-26auto merge of #19169 : aturon/rust/fds, r=alexcrichtonbors-4/+51
This PR adds some internal infrastructure to allow the private `std::sys` module to access internal representation details of `std::io`. It then exposes those details in two new, platform-specific API surfaces: `std::os::unix` and `std::os::windows`. To start with, these will provide the ability to extract file descriptors, HANDLEs, SOCKETs, and so on from `std::io` types. More functionality, and more specific platforms (e.g. `std::os::linux`) will be added over time. Closes #18897
2014-11-25Fallout from stabilizationAaron Turon-6/+4
2014-11-25Allow mutable access to wrapped internal type in Buffered*Steven Fackler-10/+26
This is necessary to e.g. set a timeout on the underlying stream.
2014-11-25auto merge of #19149 : alexcrichton/rust/issue-19091, r=aturonbors-11/+47
This change applies the conventions to unwrap listed in [RFC 430][rfc] to rename non-failing `unwrap` methods to `into_inner`. This is a breaking change, but all `unwrap` methods are retained as `#[deprecated]` for the near future. To update code rename `unwrap` method calls to `into_inner`. [rfc]: https://github.com/rust-lang/rfcs/pull/430 [breaking-change] cc #19091
2014-11-24Clean up FileType enum following enum namespacingBen S-22/+21
All of the enum components had a redundant 'Type' specifier: TypeSymlink, TypeDirectory, TypeFile. This change removes them, replacing them with a namespace: FileType::Symlink, FileType::Directory, and FileType::RegularFile. RegularFile is used instead of just File, as File by itself could be mistakenly thought of as referring to the struct. [breaking-change]
2014-11-24Don't call drop in tcpstream docsSteve Klabnik-6/+10
This suggests that you must call it, which is normally not what you want to do.
2014-11-23std: Add a new top-level thread_local moduleAlex Crichton-8/+23
This commit removes the `std::local_data` module in favor of a new `std::thread_local` module providing thread local storage. The module provides two variants of TLS: one which owns its contents and one which is based on scoped references. Each implementation has pros and cons listed in the documentation. Both flavors have accessors through a function called `with` which yield a reference to a closure provided. Both flavors also panic if a reference cannot be yielded and provide a function to test whether an access would panic or not. This is an implementation of [RFC 461][rfc] and full details can be found in that RFC. This is a breaking change due to the removal of the `std::local_data` module. All users can migrate to the new thread local system like so: thread_local!(static FOO: Rc<RefCell<Option<T>>> = Rc::new(RefCell::new(None))) The old `local_data` module inherently contained the `Rc<RefCell<Option<T>>>` as an implementation detail which must now be explicitly stated by users. [rfc]: https://github.com/rust-lang/rfcs/pull/461 [breaking-change]
2014-11-23Rename unwrap functions to into_innerAlex Crichton-11/+47
This change applies the conventions to unwrap listed in [RFC 430][rfc] to rename non-failing `unwrap` methods to `into_inner`. This is a breaking change, but all `unwrap` methods are retained as `#[deprecated]` for the near future. To update code rename `unwrap` method calls to `into_inner`. [rfc]: https://github.com/rust-lang/rfcs/pull/430 [breaking-change] Closes #13159 cc #19091
2014-11-21sys: reveal std::io representation to sys moduleAaron Turon-4/+51
This commit adds a `AsInner` trait to `sys_common` and provides implementations on many `std::io` types. This is a building block for exposing platform-specific APIs that hook into `std::io` types.
2014-11-20Disable dubious pipe testAaron Turon-1/+1
2014-11-20Make most of std::rt privateAaron Turon-4/+4
Previously, the entire runtime API surface was publicly exposed, but that is neither necessary nor desirable. This commit hides most of the module, using librustrt directly as needed. The arrangement will need to be revisited when rustrt is pulled into std. [breaking-change]
2014-11-20Fallout from libgreen and libnative removalAaron Turon-2/+0
2014-11-18std: Stabilize std::fmtAlex Crichton-7/+5
This commit applies the stabilization of std::fmt as outlined in [RFC 380][rfc]. There are a number of breaking changes as a part of this commit which will need to be handled to migrated old code: * A number of formatting traits have been removed: String, Bool, Char, Unsigned, Signed, and Float. It is recommended to instead use Show wherever possible or to use adaptor structs to implement other methods of formatting. * The format specifier for Boolean has changed from `t` to `b`. * The enum `FormatError` has been renamed to `Error` as well as becoming a unit struct instead of an enum. The `WriteError` variant no longer exists. * The `format_args_method!` macro has been removed with no replacement. Alter code to use the `format_args!` macro instead. * The public fields of a `Formatter` have become read-only with no replacement. Use a new formatting string to alter the formatting flags in combination with the `write!` macro. The fields can be accessed through accessor methods on the `Formatter` structure. Other than these breaking changes, the contents of std::fmt should now also all contain stability markers. Most of them are still #[unstable] or #[experimental] [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0380-stabilize-std-fmt.md [breaking-change] Closes #18904
2014-11-19Make os::getcwd() return IoResult<Path>Barosl Lee-4/+5
os::getcwd() panics if the current directory is not available. According to getcwd(3), there are three cases: - EACCES: Permission denied. - ENOENT: The current working directory has been removed. - ERANGE: The buffer size is less than the actual absolute path. This commit makes os::getcwd() return IoResult<Path>, not just Path, preventing it from panicking. As os::make_absolute() depends on os::getcwd(), it is also modified to return IoResult<Path>. Fixes #16946. [breaking-change]
2014-11-18implement Writer for Vec<u8>Daniel Micay-43/+54
The trait has an obvious, sensible implementation directly on vectors so the MemWriter wrapper is unnecessary. This will halt the trend towards providing all of the vector methods on MemWriter along with eliminating the noise caused by conversions between the two types. It also provides the useful default Writer methods on Vec<u8>. After the type is removed and code has been migrated, it would make sense to add a new implementation of MemWriter with seeking support. The simple use cases can be covered with vectors alone, and ones with the need for seeks can use a new MemWriter implementation.
2014-11-18rollup merge of #19016: gkoz/use_util_copyJakub Bukaj-9/+1
This code is identical to io::util::copy()
2014-11-17Return proper errors with update_errGleb Kozyrev-1/+1
2014-11-17Remove duplicate code by using util::copy()Gleb Kozyrev-9/+1
2014-11-17Switch to purely namespaced enumsSteven Fackler-0/+18
This breaks code that referred to variant names in the same namespace as their enum. Reexport the variants in the old location or alter code to refer to the new locations: ``` pub enum Foo { A, B } fn main() { let a = A; } ``` => ``` pub use self::Foo::{A, B}; pub enum Foo { A, B } fn main() { let a = A; } ``` or ``` pub enum Foo { A, B } fn main() { let a = Foo::A; } ``` [breaking-change]
2014-11-17Fix fallout from coercion removalNick Cameron-294/+294
2014-11-16Fix warningsJakub Bukaj-1/+1
2014-11-16rollup merge of #18985: alexcrichton/issue-18900Jakub Bukaj-24/+22
2014-11-16rollup merge of #18976: bjz/rfc369-numericsJakub Bukaj-3/+2
2014-11-16auto merge of #18788 : ricky26/rust/master, r=aturonbors-11/+24
This moves chars() and lines() out of Buffer and into separate traits (CharsBuffer and LinesBuffer respectively) - this matches the pattern used for bytes() on Reader (with BytesReader). (I came across this when I wanted a trait object of a Buffer, so that I could use read_line(); rustc errors about std::io::Buffer not being object-safe.) [breaking-change] Any uses of Buffer::lines() will need to use the new trait std::io::LinesBuffer. The same is true for Buffer::chars() with std::io::CharsBuffer.
2014-11-16Move FromStr to core::strBrendan Zabarauskas-3/+2
2014-11-15std: Fix a flaky test on OSX 10.10Alex Crichton-24/+22
This test was somewhat sketchy already with a `loop` around `write`, so this just adds some explicit synchronization to only call `write` once and guarantee that the error happens. Closes #18900
2014-11-14auto merge of #18880 : barosl/rust/doc-fail-to-panic, r=alexcrichtonbors-2/+2
I found some occurrences of "failure" and "fails" in the documentation. I changed them to "panics" if it means a task panic. Otherwise I left it as is, or changed it to "errors" to clearly distinguish them. Also, I made a minor fix that is breaking the layout of a module page. "Example" is shown in an irrelevant place from the following page: http://doc.rust-lang.org/std/os/index.html
2014-11-13Make std::io::Buffer object-safe.Ricky Taylor-11/+24
[breaking-change] Any uses of Buffer::lines() and Buffer::chars() will need to use the new trait std::io::BufferPrelude.