about summary refs log tree commit diff
path: root/src/libstd/io
AgeCommit message (Collapse)AuthorLines
2014-05-27std: Rename strbuf operations to stringRicho Healey-28/+28
[breaking-change]
2014-05-27std: Remove String's to_ownedRicho Healey-1/+1
2014-05-25libstd: Remove unnecessary re-exports under std::stdKevin Ballard-3/+3
2014-05-24core: rename strbuf::StrBuf to string::StringRicho Healey-9/+9
[breaking-change]
2014-05-23std: Move running_on_valgrind to rt::util. #1457Brian Anderson-1/+1
[breaking-change]
2014-05-22auto merge of #14357 : huonw/rust/spelling, r=pnkfelixbors-7/+7
The span on a inner doc-comment would point to the next token, e.g. the span for the `a` line points to the `b` line, and the span of `b` points to the `fn`. ```rust //! a //! b fn bar() {} ```
2014-05-22libcore: Remove all uses of `~str` from `libcore`.Patrick Walton-7/+8
[breaking-change]
2014-05-22libstd: Remove `~str` from all `libstd` modules except `fmt` and `str`.Patrick Walton-124/+144
2014-05-22Spelling/doc formatting fixes.Huon Wilson-7/+7
2014-05-20Add .isatty() method to StdReaderKevin Ballard-0/+10
StdWriter has .isatty(). StdReader can trivially vend the same function, and someone asked today on IRC how to call isatty() on stdin.
2014-05-16rustc: Stop leaking enum variants into childrenAlex Crichton-3/+3
This plugs a leak where resolve was treating enums defined in parent modules as in-scope for all children modules when resolving a pattern identifier. This eliminates the code path in resolve entirely. If this breaks any existing code, then it indicates that the variants need to be explicitly imported into the module. Closes #14221 [breaking-change]
2014-05-15core: Update all tests for fmt movementAlex Crichton-2/+2
2014-05-15Updates with core::fmt changesAlex Crichton-16/+14
1. Wherever the `buf` field of a `Formatter` was used, the `Formatter` is used instead. 2. The usage of `write_fmt` is minimized as much as possible, the `write!` macro is preferred wherever possible. 3. Usage of `fmt::write` is minimized, favoring the `write!` macro instead.
2014-05-15std: Add an adaptor for Writer => FormatWriterAlex Crichton-0/+36
This new method, write_fmt(), is the one way to write a formatted list of arguments into a Writer stream. This has a special adaptor to preserve errors which occur on the writer. All macros will be updated to use this method explicitly.
2014-05-15std: Delete unused fileBrian Anderson-52/+0
2014-05-15std: Modify TempDir to not fail on drop. Closes #12628Brian Anderson-10/+47
After discussion with Alex, we think the proper policy is for dtors to not fail. This is consistent with C++. BufferedWriter already does this, so this patch modifies TempDir to not fail in the dtor, adding a `close` method for handling errors on destruction.
2014-05-14Process::new etc should support non-utf8 commands/argsAaron Turon-306/+291
The existing APIs for spawning processes took strings for the command and arguments, but the underlying system may not impose utf8 encoding, so this is overly limiting. The assumption we actually want to make is just that the command and arguments are viewable as [u8] slices with no interior NULLs, i.e., as CStrings. The ToCStr trait is a handy bound for types that meet this requirement (such as &str and Path). However, since the commands and arguments are often a mixture of strings and paths, it would be inconvenient to take a slice with a single T: ToCStr bound. So this patch revamps the process creation API to instead use a builder-style interface, called `Command`, allowing arguments to be added one at a time with differing ToCStr implementations for each. The initial cut of the builder API has some drawbacks that can be addressed once issue #13851 (libstd as a facade) is closed. These are detailed as FIXMEs. Closes #11650. [breaking-change]
2014-05-14auto merge of #14009 : jcmoyer/rust/bitflags-complement, r=alexcrichtonbors-1/+1
I feel that this is a very vital, missing piece of functionality. This adds on to #13072. Only bits used in the definition of the bitflag are considered for the universe set. This is a bit safer than simply inverting all of the bits in the wrapped value. ```rust bitflags!(flags Flags: u32 { FlagA = 0x00000001, FlagB = 0x00000010, FlagC = 0x00000100, FlagABC = FlagA.bits | FlagB.bits | FlagC.bits }) ... // `Not` implements set complement assert!(!(FlagB | FlagC) == FlagA); // `all` and `is_all` are the inverses of `empty` and `is_empty` assert!(Flags::all() - FlagA == !FlagA); assert!(FlagABC.is_all()); ```
2014-05-14auto merge of #14186 : omasanori/rust/suppress-warnings, r=alexcrichtonbors-1/+1
2014-05-14Implement set complement and universe for bitflagsJ.C. Moyer-1/+1
2014-05-13auto merge of #13127 : kballard/rust/read_at_least, r=alexcrichtonbors-82/+251
Reader.read_at_least() ensures that at least a given number of bytes have been read. The most common use-case for this is ensuring at least 1 byte has been read. If the reader returns 0 enough times in a row, a new error kind NoProgress will be returned instead of looping infinitely. This change is necessary in order to properly support Readers that repeatedly return 0, either because they're broken, or because they're attempting to do a non-blocking read on some resource that never becomes available. Also add .push() and .push_at_least() methods. push() is like read() but the results are appended to the passed Vec. Remove Reader.fill() and Reader.push_exact() as they end up being thin wrappers around read_at_least() and push_at_least(). [breaking-change]
2014-05-13io: Add .read_at_least() to ReaderKevin Ballard-82/+251
Reader.read_at_least() ensures that at least a given number of bytes have been read. The most common use-case for this is ensuring at least 1 byte has been read. If the reader returns 0 enough times in a row, a new error kind NoProgress will be returned instead of looping infinitely. This change is necessary in order to properly support Readers that repeatedly return 0, either because they're broken, or because they're attempting to do a non-blocking read on some resource that never becomes available. Also add .push() and .push_at_least() methods. push() is like read() but the results are appended to the passed Vec. Remove Reader.fill() and Reader.push_exact() as they end up being thin wrappers around read_at_least() and push_at_least(). [breaking-change]
2014-05-13io: Implement process wait timeoutsAlex Crichton-59/+131
This implements set_timeout() for std::io::Process which will affect wait() operations on the process. This follows the same pattern as the rest of the timeouts emerging in std::io::net. The implementation was super easy for everything except libnative on unix (backwards from usual!), which required a good bit of signal handling. There's a doc comment explaining the strategy in libnative. Internally, this also required refactoring the "helper thread" implementation used by libnative to allow for an extra helper thread (not just the timer). This is a breaking change in terms of the io::Process API. It is now possible for wait() to fail, and subsequently wait_with_output(). These two functions now return IoResult<T> due to the fact that they can time out. Additionally, the wait_with_output() function has moved from taking `&mut self` to taking `self`. If a timeout occurs while waiting with output, the semantics are undesirable in almost all cases if attempting to re-wait on the process. Equivalent functionality can still be achieved by dealing with the output handles manually. [breaking-change] cc #13523
2014-05-14Suppress a "unused variable" warning.OGINO Masanori-1/+1
Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
2014-05-12auto merge of #13919 : thomaslee/rust/thomaslee_proposed_tcpstream_open, ↵bors-96/+264
r=alexcrichton Been meaning to try my hand at something like this for a while, and noticed something similar mentioned as part of #13537. The suggestion on the original ticket is to use `TcpStream::open(&str)` to pass in a host + port string, but seems a little cleaner to pass in host and port separately -- so a signature like `TcpStream::open(&str, u16)`. Also means we can use std::io::net::addrinfo directly instead of using e.g. liburl to parse the host+port pair from a string. One outstanding issue in this PR that I'm not entirely sure how to address: in open_timeout, the timeout_ms will apply for every A record we find associated with a hostname -- probably not the intended behavior, but I didn't want to waste my time on elaborate alternatives until the general idea was a-OKed. :) Anyway, perhaps there are other reasons for us to prefer the original proposed syntax, but thought I'd get some thoughts on this. Maybe there are some solid reasons to prefer using liburl to do this stuff.
2014-05-12Document a possible way in which connect_timout may change in the futureTom Lee-0/+3
2014-05-12Try to parse TcpStream::connect 'host' parameter as an IP.Tom Lee-1/+4
Fall back to get_host_addresses to try a DNS lookup if we can't parse it as an IP address.
2014-05-12Easier interface for TCP ::connect and ::bind.Tom Lee-96/+258
Prior to this commit, TcpStream::connect and TcpListener::bind took a single SocketAddr argument. This worked well enough, but the API felt a little too "low level" for most simple use cases. A great example is connecting to rust-lang.org on port 80. Rust users would need to: 1. resolve the IP address of rust-lang.org using io::net::addrinfo::get_host_addresses. 2. check for errors 3. if all went well, use the returned IP address and the port number to construct a SocketAddr 4. pass this SocketAddr to TcpStream::connect. I'm modifying the type signature of TcpStream::connect and TcpListener::bind so that the API is a little easier to use. TcpStream::connect now accepts two arguments: a string describing the host/IP of the host we wish to connect to, and a u16 representing the remote port number. Similarly, TcpListener::bind has been modified to take two arguments: a string describing the local interface address (e.g. "0.0.0.0" or "127.0.0.1") and a u16 port number. Here's how to port your Rust code to use the new TcpStream::connect API: // old ::connect API let addr = SocketAddr{ip: Ipv4Addr{127, 0, 0, 1}, port: 8080}; let stream = TcpStream::connect(addr).unwrap() // new ::connect API (minimal change) let addr = SocketAddr{ip: Ipv4Addr{127, 0, 0, 1}, port: 8080}; let stream = TcpStream::connect(addr.ip.to_str(), addr.port()).unwrap() // new ::connect API (more compact) let stream = TcpStream::connect("127.0.0.1", 8080).unwrap() // new ::connect API (hostname) let stream = TcpStream::connect("rust-lang.org", 80) Similarly, for TcpListener::bind: // old ::bind API let addr = SocketAddr{ip: Ipv4Addr{0, 0, 0, 0}, port: 8080}; let mut acceptor = TcpListener::bind(addr).listen(); // new ::bind API (minimal change) let addr = SocketAddr{ip: Ipv4Addr{0, 0, 0, 0}, port: 8080}; let mut acceptor = TcpListener::bind(addr.ip.to_str(), addr.port()).listen() // new ::bind API (more compact) let mut acceptor = TcpListener::bind("0.0.0.0", 8080).listen() [breaking-change]
2014-05-12Test fixes from rollupAlex Crichton-1/+0
Closes #14163 (Fix typos in rustc manpage) Closes #14161 (Add the patch number to version strings. Closes #13289) Closes #14156 (rustdoc: Fix hiding implementations of traits) Closes #14152 (add shebang to scripts that have execute bit set) Closes #14150 (libcore: remove fails from slice.rs and remove duplicated length checking) Closes #14147 (Make ProcessOutput Eq, TotalEq, Clone) Closes #14142 (doc: updates rust manual (loop to continue)) Closes #14141 (doc: Update the linkage documentation) Closes #14139 (Remove an unnecessary .move_iter().collect()) Closes #14136 (Two minor fixes in parser.rs) Closes #14130 (Fixed typo in comments of driver.rs) Closes #14128 (Add `stat` method to `std::io::fs::File` to stat without a Path.) Closes #14114 (rustdoc: List macros in the sidebar) Closes #14113 (shootout-nbody improvement) Closes #14112 (Improved example code in Option) Closes #14104 (Remove reference to MutexArc) Closes #14087 (emacs: highlight `macro_name!` in macro invocations using [] delimiters)
2014-05-12Add `stat` method to `std::io::fs::File` to stat without a Path.Yuri Kunde Schlesner-9/+14
The `FileStat` struct contained a `path` field, which was filled by the `stat` and `lstat` function. Since this field isn't in fact returned by the operating system (it was copied from the paths passed to the functions) it was removed, as in the `fstat` case we aren't working with a `Path`, but directly with a fd. If your code used the `path` field of `FileStat` you will now have to manually store the path passed to `stat` along with the returned struct. [breaking-change]
2014-05-12Make ProcessOutput Eq, TotalEq, CloneYehuda Katz-0/+1
2014-05-11core: Remove the cast moduleAlex Crichton-13/+14
This commit revisits the `cast` module in libcore and libstd, and scrutinizes all functions inside of it. The result was to remove the `cast` module entirely, folding all functionality into the `mem` module. Specifically, this is the fate of each function in the `cast` module. * transmute - This function was moved to `mem`, but it is now marked as #[unstable]. This is due to planned changes to the `transmute` function and how it can be invoked (see the #[unstable] comment). For more information, see RFC 5 and #12898 * transmute_copy - This function was moved to `mem`, with clarification that is is not an error to invoke it with T/U that are different sizes, but rather that it is strongly discouraged. This function is now #[stable] * forget - This function was moved to `mem` and marked #[stable] * bump_box_refcount - This function was removed due to the deprecation of managed boxes as well as its questionable utility. * transmute_mut - This function was previously deprecated, and removed as part of this commit. * transmute_mut_unsafe - This function doesn't serve much of a purpose when it can be achieved with an `as` in safe code, so it was removed. * transmute_lifetime - This function was removed because it is likely a strong indication that code is incorrect in the first place. * transmute_mut_lifetime - This function was removed for the same reasons as `transmute_lifetime` * copy_lifetime - This function was moved to `mem`, but it is marked `#[unstable]` now due to the likelihood of being removed in the future if it is found to not be very useful. * copy_mut_lifetime - This function was also moved to `mem`, but had the same treatment as `copy_lifetime`. * copy_lifetime_vec - This function was removed because it is not used today, and its existence is not necessary with DST (copy_lifetime will suffice). In summary, the cast module was stripped down to these functions, and then the functions were moved to the `mem` module. transmute - #[unstable] transmute_copy - #[stable] forget - #[stable] copy_lifetime - #[unstable] copy_mut_lifetime - #[unstable] [breaking-change]
2014-05-09auto merge of #14046 : alexcrichton/rust/ignore-a-test-on-freebsd, r=kballardbors-13/+18
This test runs successfully manually, but the bots are having trouble getting this test to pass. Ignore it on freebsd for now.
2014-05-09auto merge of #14035 : alexcrichton/rust/experimental, r=huonwbors-0/+9
This was intended as part of the I/O timeouts commit, but it was mistakenly forgotten. The type of the timeout argument is not guaranteed to remain constant into the future.
2014-05-08Handle fallout in documentationKevin Ballard-1/+1
Tweak the tutorial's section on vectors and strings, to slightly clarify the difference between fixed-size vectors, vectors, and slices.
2014-05-08Handle fallout in io::net::addrinfo, io::process, and rt::rtioKevin Ballard-5/+5
API Changes: - get_host_addresses() returns IoResult<Vec<IpAddr>> - Process.extra_io is Vec<Option<io::PipeStream>>
2014-05-08std: Ignore a flaky test on freebsdAlex Crichton-13/+18
This test runs successfully manually, but the bots are having trouble getting this test to pass. Ignore it on freebsd for now.
2014-05-08std: Mark timeout methods experimentalAlex Crichton-0/+9
This was intended as part of the I/O timeouts commit, but it was mistakenly forgotten. The type of the timeout argument is not guaranteed to remain constant into the future.
2014-05-07native: Implement timeouts for windows pipesAlex Crichton-1/+8
This is the last remaining networkig object to implement timeouts for. This takes advantage of the CancelIo function and the already existing asynchronous I/O functionality of pipes.
2014-05-07std: Add I/O timeouts to networking objectsAlex Crichton-15/+404
These timeouts all follow the same pattern as established by the timeouts on acceptors. There are three methods: set_timeout, set_read_timeout, and set_write_timeout. Each of these sets a point in the future after which operations will time out. Timeouts with cloned objects are a little trickier. Each object is viewed as having its own timeout, unaffected by other objects' timeouts. Additionally, timeouts do not propagate when a stream is cloned or when a cloned stream has its timeouts modified. This commit is just the public interface which will be exposed for timeouts, the implementation will come in later commits.
2014-05-07auto merge of #13964 : alexcrichton/rust/more-buffers, r=brsonbors-1/+63
This will allow methods like read_line() on RefReader, LimitReader, etc.
2014-05-07auto merge of #13751 : alexcrichton/rust/io-close-read, r=brsonbors-14/+201
Two new methods were added to TcpStream and UnixStream: fn close_read(&mut self) -> IoResult<()>; fn close_write(&mut self) -> IoResult<()>; These two methods map to shutdown()'s behavior (the system call on unix), closing the reading or writing half of a duplex stream. These methods are primarily added to allow waking up a pending read in another task. By closing the reading half of a connection, all pending readers will be woken up and will return with EndOfFile. The close_write() method was added for symmetry with close_read(), and I imagine that it will be quite useful at some point. Implementation-wise, librustuv got the short end of the stick this time. The native versions just delegate to the shutdown() syscall (easy). The uv versions can leverage uv_shutdown() for tcp/unix streams, but only for closing the writing half. Closing the reading half is done through some careful dancing to wake up a pending reader. As usual, windows likes to be different from unix. The windows implementation uses shutdown() for sockets, but shutdown() is not available for named pipes. Instead, CancelIoEx was used with same fancy synchronization to make sure everyone knows what's up. cc #11165
2014-05-07std: Add close_{read,write}() methods to I/OAlex Crichton-14/+201
Two new methods were added to TcpStream and UnixStream: fn close_read(&mut self) -> IoResult<()>; fn close_write(&mut self) -> IoResult<()>; These two methods map to shutdown()'s behavior (the system call on unix), closing the reading or writing half of a duplex stream. These methods are primarily added to allow waking up a pending read in another task. By closing the reading half of a connection, all pending readers will be woken up and will return with EndOfFile. The close_write() method was added for symmetry with close_read(), and I imagine that it will be quite useful at some point. Implementation-wise, librustuv got the short end of the stick this time. The native versions just delegate to the shutdown() syscall (easy). The uv versions can leverage uv_shutdown() for tcp/unix streams, but only for closing the writing half. Closing the reading half is done through some careful dancing to wake up a pending reader. As usual, windows likes to be different from unix. The windows implementation uses shutdown() for sockets, but shutdown() is not available for named pipes. Instead, CancelIoEx was used with same fancy synchronization to make sure everyone knows what's up. cc #11165
2014-05-07core: Move Option::expect to libstd from libcoreAlex Crichton-0/+1
See #14008 for more details
2014-05-07core: Add unwrap()/unwrap_err() methods to ResultAlex Crichton-4/+6
These implementations must live in libstd right now because the fmt module has not been migrated yet. This will occur in a later PR. Just to be clear, there are new extension traits, but they are not necessary once the std::fmt module has migrated to libcore, which is a planned migration in the future.
2014-05-07core: Inherit possible string functionalityAlex Crichton-2/+1
This moves as much allocation as possible from teh std::str module into core::str. This includes essentially all non-allocating functionality, mostly iterators and slicing and such. This primarily splits the Str trait into only having the as_slice() method, adding a new StrAllocating trait to std::str which contains the relevant new allocation methods. This is a breaking change if any of the methods of "trait Str" were overriden. The old functionality can be restored by implementing both the Str and StrAllocating traits. [breaking-change]
2014-05-07std: Implement the Buffer trait for some wrappersAlex Crichton-1/+63
This will allow methods like read_line() on RefReader, LimitReader, etc.
2014-05-07auto merge of #13958 : pcwalton/rust/detilde, r=pcwaltonbors-32/+43
for `~str`/`~[]`. Note that `~self` still remains, since I forgot to add support for `Box<self>` before the snapshot. r? @brson or @alexcrichton or whoever
2014-05-06librustc: Remove `~EXPR`, `~TYPE`, and `~PAT` from the language, exceptPatrick Walton-32/+43
for `~str`/`~[]`. Note that `~self` still remains, since I forgot to add support for `Box<self>` before the snapshot. How to update your code: * Instead of `~EXPR`, you should write `box EXPR`. * Instead of `~TYPE`, you should write `Box<Type>`. * Instead of `~PATTERN`, you should write `box PATTERN`. [breaking-change]
2014-05-06auto merge of #13754 : alexcrichton/rust/net-experimental, r=brsonbors-1/+70
The underlying I/O objects implement a good deal of various options here and there for tuning network sockets and how they perform. Most of this is a relic of "whatever libuv provides", but these options are genuinely useful. It is unclear at this time whether these options should be well supported or not, or whether they have correct names or not. For now, I believe it's better to expose the functionality than to not, but all new methods are added with an #[experimental] annotation.