about summary refs log tree commit diff
path: root/src/libstd/io
AgeCommit message (Collapse)AuthorLines
2014-02-18auto merge of #12345 : huonw/rust/speeling, r=cmrbors-1/+1
2014-02-18Spellcheck library docs.Huon Wilson-1/+1
2014-02-16Implement named pipes for windows, touch up unixAlex Crichton-42/+61
* Implementation of pipe_win32 filled out for libnative * Reorganize pipes to be clone-able * Fix a few file descriptor leaks on error * Factor out some common code into shared functions * Make use of the if_ok!() macro for less indentation Closes #11201
2014-02-16Allow configuration of uid/gid/detach on processesAlex Crichton-23/+106
This just copies the libuv implementation for libnative which seems reasonable enough (uid/gid fail on windows). Closes #12082
2014-02-15auto merge of #12299 : sfackler/rust/limit-return, r=alexcrichtonbors-2/+24
This is useful in contexts like this: ```rust let size = rdr.read_be_i32() as uint; let mut limit = LimitReader::new(rdr.by_ref(), size); let thing = read_a_thing(&mut limit); assert!(limit.limit() == 0); ```
2014-02-15auto merge of #12298 : alexcrichton/rust/rustdoc-testing, r=sfacklerbors-9/+21
It's too easy to forget the `rust` tag to test something. Closes #11698
2014-02-15Add a method to LimitReader to return the limitSteven Fackler-2/+24
This is useful in contexts like this: let size = rdr.read_be_i32() as uint; let mut limit = LimitReader::new(rdr.by_ref(), size); let thing = read_a_thing(&mut limit); assert!(limit.limit() == 0);
2014-02-15auto merge of #12282 : cmr/rust/cleanup-ptr, r=huonwbors-6/+4
2014-02-15std: clean up ptr a bitCorey Richardson-6/+4
2014-02-14Fix all code examplesAlex Crichton-9/+21
2014-02-15Update LimitReader to take the Reader to wrap by valuePalmer Cox-7/+8
2014-02-15Create RefReader and RefWriter adaptor structsPalmer Cox-0/+33
RefReader and RefWriter allow a caller to pass a Reader or Writer instance by reference to generic functions that are expecting arguments by value.
2014-02-14extra: Capture stdout/stderr of tests by defaultAlex Crichton-0/+6
When tests fail, their stdout and stderr is printed as part of the summary, but this helps suppress failure messages from #[should_fail] tests and generally clean up the output of the test runner.
2014-02-14return value/use extra::test::black_box in benchmarkslpy-2/+2
2014-02-13Removed num::OrderableMichael Darakananda-2/+2
2014-02-13remove duplicate function from std::ptr (is_null, is_not_null, offset, ↵JeremyLetang-3/+4
mut_offset)
2014-02-12auto merge of #12204 : alexcrichton/rust/seek, r=pcwaltonbors-31/+80
This adopts the rules posted in #10432: 1. If a seek position is negative, then an error is generated 2. Seeks beyond the end-of-file are allowed. Future writes will fill the gap with data and future reads will return errors. 3. Seeks within the bounds of a file are fine. Closes #10432
2014-02-11Finalize the Seek APIAlex Crichton-31/+80
This adopts the rules posted in #10432: 1. If a seek position is negative, then an error is generated 2. Seeks beyond the end-of-file are allowed. Future writes will fill the gap with data and future reads will return errors. 3. Seeks within the bounds of a file are fine. Closes #10432
2014-02-11Test fixes and rebase conflictsAlex Crichton-4/+4
2014-02-11Rewrite channels yet again for upgradeabilityAlex Crichton-3/+3
This, the Nth rewrite of channels, is not a rewrite of the core logic behind channels, but rather their API usage. In the past, we had the distinction between oneshot, stream, and shared channels, but the most recent rewrite dropped oneshots in favor of streams and shared channels. This distinction of stream vs shared has shown that it's not quite what we'd like either, and this moves the `std::comm` module in the direction of "one channel to rule them all". There now remains only one Chan and one Port. This new channel is actually a hybrid oneshot/stream/shared channel under the hood in order to optimize for the use cases in question. Additionally, this also reduces the cognitive burden of having to choose between a Chan or a SharedChan in an API. My simple benchmarks show no reduction in efficiency over the existing channels today, and a 3x improvement in the oneshot case. I sadly don't have a pre-last-rewrite compiler to test out the old old oneshots, but I would imagine that the performance is comparable, but slightly slower (due to atomic reference counting). This commit also brings the bonus bugfix to channels that the pending queue of messages are all dropped when a Port disappears rather then when both the Port and the Chan disappear.
2014-02-11io -- introduce local to avoid conflicting borrowNiko Matsakis-1/+2
2014-02-11std -- replaces uses where const borrows would be requiredNiko Matsakis-17/+25
2014-02-11Move replace and swap to std::mem. Get rid of std::utilEdward Wang-5/+4
Also move Void to std::any, move drop to std::mem and reexport in prelude.
2014-02-10auto merge of #12149 : thomaslee/rust/ipaddr_deriving_iter_bytes, r=cmrbors-2/+13
This is a fairly trivial (but IMHO handy) change to implement IterBytes for IpAddr and SocketAddr. I originally stumbled across this because I wanted to use a SocketAddr as a HashMap key and discovered that I couldn't do it directly. Had to impl IterBytes on a new intermediate type to work around it.
2014-02-10IterBytes for IpAddr and SocketAddrTom Lee-2/+13
2014-02-09auto merge of #12124 : brson/rust/intrinsics, r=thestingerbors-3/+3
As mentioned https://github.com/mozilla/rust/pull/11956#issuecomment-34561655 I've taken some of the most commonly-used intrinsics and put them in a more logical place, reduced the amount of code looking in `unstable::intrinsics`. r? @thestinger
2014-02-09auto merge of #12120 : gifnksm/rust/buffered-chars, r=alexcrichtonbors-0/+45
Add `std::io::Chars` iterator and `Buffer#chars()` method
2014-02-09std: Move byteswap functions to memBrian Anderson-3/+3
2014-02-09std::io: Add `Chars` iterator for Buffer.gifnksm-0/+45
Add `std::io::Chars` iterator and `Buffer#chars()` method
2014-02-08Fix infinite loop in BufReader::read_until.Q.P.Liu-1/+9
2014-02-08Fix infinite loop in MemReader::read_until.Q.P.Liu-1/+9
2014-02-08std::fmt: convert the formatting traits to a proper self.Huon Wilson-5/+5
Poly and String have polymorphic `impl`s and so require different method names.
2014-02-05Make a double-write UDP test more robustAlex Crichton-7/+10
I have a hunch this just deadlocked the windows bots. Due to UDP being a lossy protocol, I don't think we can guarantee that the server can receive both packets, so just listen for one of them.
2014-02-05Implement clone() for TCP/UDP/Unix socketsAlex Crichton-1/+399
This is part of the overall strategy I would like to take when approaching issue #11165. The only two I/O objects that reasonably want to be "split" are the network stream objects. Everything else can be "split" by just creating another version. The initial idea I had was the literally split the object into a reader and a writer half, but that would just introduce lots of clutter with extra interfaces that were a little unnnecssary, or it would return a ~Reader and a ~Writer which means you couldn't access things like the remote peer name or local socket name. The solution I found to be nicer was to just clone the stream itself. The clone is just a clone of the handle, nothing fancy going on at the kernel level. Conceptually I found this very easy to wrap my head around (everything else supports clone()), and it solved the "split" problem at the same time. The cloning support is pretty specific per platform/lib combination: * native/win32 - uses some specific WSA apis to clone the SOCKET handle * native/unix - uses dup() to get another file descriptor * green/all - This is where things get interesting. When we support full clones of a handle, this implies that we're allowing simultaneous writes and reads to happen. It turns out that libuv doesn't support two simultaneous reads or writes of the same object. It does support *one* read and *one* write at the same time, however. Some extra infrastructure was added to just block concurrent writers/readers until the previous read/write operation was completed. I've added tests to the tcp/unix modules to make sure that this functionality is supported everywhere.
2014-02-03Fixing remaining warnings and errors throughoutAlex Crichton-10/+15
2014-02-03std: Fixing all documentationAlex Crichton-303/+245
* Stop referencing io_error * Start changing "Failure" sections to "Error" sections * Update all doc examples to work.
2014-02-03std: Fix tests with io_error usageAlex Crichton-646/+531
2014-02-03std: Remove io::io_errorAlex Crichton-802/+630
* All I/O now returns IoResult<T> = Result<T, IoError> * All formatting traits now return fmt::Result = IoResult<()> * The if_ok!() macro was added to libstd
2014-02-02std: rename fmt::Default to `Show`.Huon Wilson-1/+1
This is a better name with which to have a #[deriving] mode. Decision in: https://github.com/mozilla/rust/wiki/Meeting-weekly-2014-01-28
2014-02-01Optimize u64_to_{le,be}_bytesBjörn Steinbrink-28/+14
LLVM fails to properly optimize the shifts used to convert the source value to the right endianess. The resulting assembly copies the value to the stack one byte at a time even when there's no conversion required (e.g. u64_to_le_bytes on a little endian machine). Instead of doing the conversion ourselves using shifts, we can use the existing intrinsics to perform the endianess conversion and then transmute the value to get a fixed vector of its bytes. Before: test be_i8 ... bench: 21442 ns/iter (+/- 70) test be_i16 ... bench: 21447 ns/iter (+/- 45) test be_i32 ... bench: 23832 ns/iter (+/- 63) test be_i64 ... bench: 26887 ns/iter (+/- 267) test le_i8 ... bench: 21442 ns/iter (+/- 56) test le_i16 ... bench: 21448 ns/iter (+/- 36) test le_i32 ... bench: 23825 ns/iter (+/- 153) test le_i64 ... bench: 26271 ns/iter (+/- 138) After: test be_i8 ... bench: 21438 ns/iter (+/- 10) test be_i16 ... bench: 21441 ns/iter (+/- 15) test be_i32 ... bench: 19057 ns/iter (+/- 6) test be_i64 ... bench: 21439 ns/iter (+/- 34) test le_i8 ... bench: 21438 ns/iter (+/- 19) test le_i16 ... bench: 21439 ns/iter (+/- 8) test le_i32 ... bench: 21439 ns/iter (+/- 19) test le_i64 ... bench: 21438 ns/iter (+/- 22)
2014-01-31Fix minor doc typosVirgile Andreani-1/+1
2014-01-31auto merge of #11918 : omasanori/rust/reduce-warnings, r=alexcrichtonbors-8/+4
Moving forward to green waterfall.
2014-01-29auto merge of #11672 : bjz/rust/remove-times, r=brsonbors-10/+10
`Times::times` was always a second-class loop because it did not support the `break` and `continue` operations. Its playful appeal (which I liked) was then lost after `do` was disabled for closures. It's time to let this one go.
2014-01-30Remove Times traitBrendan Zabarauskas-10/+10
`Times::times` was always a second-class loop because it did not support the `break` and `continue` operations. Its playful appeal was then lost after `do` was disabled for closures. It's time to let this one go.
2014-01-29auto merge of #11893 : Armavica/rust/copyable-cloneable, r=huonwbors-3/+3
I found awkward to have `MutableCloneableVector` and `CloneableIterator` on the one hand, and `CopyableVector` etc. on the other hand. The concerned traits are: * `CopyableVector` --> `CloneableVector` * `OwnedCopyableVector` --> `OwnedCloneableVector` * `ImmutableCopyableVector` --> `ImmutableCloneableVector` * `CopyableTuple` --> `CloneableTuple`
2014-01-30Prefix _ to unused variables.OGINO Masanori-4/+4
Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
2014-01-30Remove unused imports.OGINO Masanori-4/+0
Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
2014-01-29auto merge of #11754 : alexcrichton/rust/unused-result, r=brsonbors-3/+3
The general consensus is that we want to move away from conditions for I/O, and I propose a two-step plan for doing so: 1. Warn about unused `Result` types. When all of I/O returns `Result`, it will require you inspect the return value for an error *only if* you have a result you want to look at. By default, for things like `write` returning `Result<(), Error>`, these will all go silently ignored. This lint will prevent blind ignorance of these return values, letting you know that there's something you should do about them. 2. Implement a `try!` macro: ``` macro_rules! try( ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) }) ) ``` With these two tools combined, I feel that we get almost all the benefits of conditions. The first step (the lint) is a sanity check that you're not ignoring return values at callsites. The second step is to provide a convenience method of returning early out of a sequence of computations. After thinking about this for awhile, I don't think that we need the so-called "do-notation" in the compiler itself because I think it's just *too* specialized. Additionally, the `try!` macro is super lightweight, easy to understand, and works almost everywhere. As soon as you want to do something more fancy, my answer is "use match". Basically, with these two tools in action, I would be comfortable removing conditions. What do others think about this strategy? ---- This PR specifically implements the `unused_result` lint. I actually added two lints, `unused_result` and `unused_must_use`, and the first commit has the rationale for why `unused_result` is turned off by default.
2014-01-29Flag Result as #[must_use] and deal with fallout.Alex Crichton-3/+3
2014-01-29Removing do keyword from libstd and librustcScott Lawrence-80/+80