about summary refs log tree commit diff
path: root/src/libstd/io
AgeCommit message (Collapse)AuthorLines
2014-09-03Fix spelling errors and capitalization.Joseph Crail-1/+1
2014-09-03Print file permissions in octal form.Jonas Hietala-2/+23
Closes #16943.
2014-09-03Remove cross-borrowing for traits.Nick Cameron-1/+1
Closes #15349 [breaking-change] Trait objects are no longer implicitly coerced from Box<T> to &T. You must make an explicit coercion using `&*`.
2014-08-31Have std::io::TempDir::new and new_in return IoResultSimon Sapin-9/+13
This allows using `try!()` [breaking-change] Fixes #16875
2014-08-29Register new snapshotsAlex Crichton-111/+0
2014-08-29Relax lifetime bounds on Reader/Writer impls for trait boxesBrian Koropoff-0/+16
Cargo needs this to be able to instantiate `TerminfoTerminal<Box<Writer+'a>>` for 'a other than 'static.
2014-08-28auto merge of #16664 : aturon/rust/stabilize-option-result, r=alexcrichtonbors-4/+4
Per API meeting https://github.com/rust-lang/meeting-minutes/blob/master/Meeting-API-review-2014-08-13.md # Changes to `core::option` Most of the module is marked as stable or unstable; most of the unstable items are awaiting resolution of conventions issues. However, a few methods have been deprecated, either due to lack of use or redundancy: * `take_unwrap`, `get_ref` and `get_mut_ref` (redundant, and we prefer for this functionality to go through an explicit .unwrap) * `filtered` and `while` * `mutate` and `mutate_or_set` * `collect`: this functionality is being moved to a new `FromIterator` impl. # Changes to `core::result` Most of the module is marked as stable or unstable; most of the unstable items are awaiting resolution of conventions issues. * `collect`: this functionality is being moved to a new `FromIterator` impl. * `fold_` is deprecated due to lack of use * Several methods found in `core::option` are added here, including `iter`, `as_slice`, and variants. Due to deprecations, this is a: [breaking-change]
2014-08-28auto merge of #16626 : ruud-v-a/rust/duration-reform, r=brsonbors-3/+3
This changes the internal representation of `Duration` from days: i32, secs: i32, nanos: u32 to secs: i64, nanos: i32 This resolves #16466. Note that `nanos` is an `i32` and not `u32` as suggested, because `i32` is easier to deal with, and it is not exposed anyway. Some methods now take `i64` instead of `i32` due to the increased range. Some methods, like `num_milliseconds`, now return an `Option<i64>` instead of `i64`, because the range of `Duration` is now larger than e.g. 2^63 milliseconds. A few remarks: - Negating `MIN` is impossible. I chose to return `MAX` as `-MIN`, but it is one nanosecond less than the actual negation. Is this the desired behaviour? - In `std::io::timer`, some functions accept a `Duration`, which is internally converted into a number of milliseconds. However, the range of `Duration` is now larger than 2^64 milliseconds. There is already a FIXME in the file that this should be addressed (without a ticket number though). I chose to silently use 0 ms if the duration is too long. Is that right, as long as the backend still uses milliseconds? - Negative durations are not formatted correctly, but they were not formatted correctly before either.
2014-08-28Fallout from stabilizing core::optionAaron Turon-4/+4
2014-08-27Implement generalized object and type parameter bounds (Fixes #16462)Niko Matsakis-9/+121
2014-08-26Use temp vars for implicit coercion to ^[T]Nick Cameron-43/+73
2014-08-24native: clone/close_accept for win32 pipesAlex Crichton-2/+3
This commits takes a similar strategy to the previous commit to implement close_accept and clone for the native win32 pipes implementation. Closes #15595
2014-08-24native: Implement clone/close_accept for unixAlex Crichton-0/+227
This commits implements {Tcp,Unix}Acceptor::{clone,close_accept} methods for unix. A windows implementation is coming in a later commit. The clone implementation is based on atomic reference counting (as with all other clones), and the close_accept implementation is based on selecting on a self-pipe which signals that a close has been seen.
2014-08-23Complete renaming of win32 to windowsVadim Chugunov-1/+1
2014-08-21libstd: Limit Duration range to i64 milliseconds.Ruud van Asseldonk-15/+3
This enables `num_milliseconds` to return an `i64` again instead of `Option<i64>`, because it is guaranteed not to overflow. The Duration range is now rougly 300e6 years (positive and negative), whereas it was 300e9 years previously. To put these numbers in perspective, 300e9 years is about 21 times the age of the universe (according to Wolfram|Alpha). 300e6 years is about 1/15 of the age of the earth (according to Wolfram|Alpha).
2014-08-20Add #[repr(C)] to all the things!Corey Richardson-0/+1
2014-08-20libstd: Refactor Duration.Ruud van Asseldonk-6/+18
This changes the internal representation of `Duration` from days: i32, secs: i32, nanos: u32 to secs: i64, nanos: i32 This resolves #16466. Some methods now take `i64` instead of `i32` due to the increased range. Some methods, like `num_milliseconds`, now return an `Option<i64>` instead of `i64`, because the range of `Duration` is now larger than e.g. 2^63 milliseconds.
2014-08-18Explain EOF behavior in File.eof().Steve Klabnik-1/+6
Fies #16239.
2014-08-17auto merge of #16498 : Kimundi/rust/inline-utf-encoding, r=alexcrichtonbors-1/+1
The first commit improves code generation through a few changes: - The `#[inline]` attributes allow llvm to constant fold the encoding step away in certain situations. For example, code like this changes from a call to `encode_utf8` in a inner loop to the pushing of a byte constant: ```rust let mut s = String::new(); for _ in range(0u, 21) { s.push_char('a'); } ``` - Both methods changed their semantic from causing run time failure if the target buffer is not large enough to returning `None` instead. This makes llvm no longer emit code for causing failure for these methods. - A few debug `assert!()` calls got removed because they affected code generation due to unwinding, and where basically unnecessary with today's sound handling of `char` as a Unicode scalar value. ~~The second commit is optional. It changes the methods from regular indexing with the `dst[i]` syntax to unsafe indexing with `dst.unsafe_mut_ref(i)`. This does not change code generation directly - in both cases llvm is smart enough to see that there can never be an out-of-bounds access. But it makes it emit a `nounwind` attribute for the function. However, I'm not sure whether that is a real improvement, so if there is any objection to this I'll remove the commit.~~ This changes how the methods behave on a too small buffer, so this is a [breaking-change]
2014-08-16librustc: Forbid external crates, imports, and/or items from beingPatrick Walton-9/+1
declared with the same name in the same scope. This breaks several common patterns. First are unused imports: use foo::bar; use baz::bar; Change this code to the following: use baz::bar; Second, this patch breaks globs that import names that are shadowed by subsequent imports. For example: use foo::*; // including `bar` use baz::bar; Change this code to remove the glob: use foo::{boo, quux}; use baz::bar; Or qualify all uses of `bar`: use foo::{boo, quux}; use baz; ... baz::bar ... Finally, this patch breaks code that, at top level, explicitly imports `std` and doesn't disable the prelude. extern crate std; Because the prelude imports `std` implicitly, there is no need to explicitly import it; just remove such directives. The old behavior can be opted into via the `import_shadowing` feature gate. Use of this feature gate is discouraged. This implements RFC #116. Closes #16464. [breaking-change]
2014-08-16Optimized IR generation for UTF-8 and UTF-16 encodingMarvin Löbel-1/+1
- Both can now be inlined and constant folded away - Both can no longer cause failure - Both now return an `Option` instead Removed debug `assert!()`s over the valid ranges of a `char` - It affected optimizations due to unwinding - Char handling is now sound enought that they became uneccessary
2014-08-14std::io::util cleanup + fixesSteven Fackler-18/+38
* Fix `LimitReader`'s `Buffer::consume` impl to avoid limit underflow * Make `MultiWriter` fail fast instead of always running through each `Writer`. This may or may not be what we want, but it at least doesn't throw any errors encountered in later `Writer`s into oblivion. * Prevent `IterReader`'s `Reader::read` impl from returning EOF if given an empty buffer. [breaking-change]
2014-08-14auto merge of #16332 : brson/rust/slicestab, r=aturonbors-11/+11
This implements some of the recommendations from https://github.com/rust-lang/meeting-minutes/blob/master/Meeting-API-review-2014-08-06.md. Explanation in commits.
2014-08-13std: Fix build errorsBrian Anderson-2/+2
2014-08-13std: Make connect_timeout return Err on zero durationBrian Anderson-12/+16
[breaking-change]
2014-08-13Fix various fallout from timer changesBrian Anderson-9/+16
2014-08-13std: connect_timeout requires a positive DurationBrian Anderson-9/+27
This is only breaking if you were previously specifying a duration of zero for some mysterious reason. [breaking-change]
2014-08-13std: Make the TCP/UDP connect_timeout methods take DurationBrian Anderson-16/+24
[breaking-change]
2014-08-13std: Clarify what timers do with zero and negative durationsBrian Anderson-16/+83
Add tests. Also fix a bunch of broken time tests.
2014-08-13std: Restore missing timer examplesBrian Anderson-0/+52
2014-08-13std: Remove ms-taking methods from timersBrian Anderson-172/+49
2014-08-13std: Update Duration from upstreamBrian Anderson-25/+9
From rust-chrono 4f34003e03e259bd5cbda0cb4d35325861307cc6
2014-08-13std: Add sleep, oneshot and periodic timers, taking DurationBrian Anderson-0/+97
2014-08-13std: Rename sleep, periodic, and oneshot timers to sleep_ms, etc.Brian Anderson-55/+55
Rename io::timer::sleep, Timer::sleep, Timer::oneshot, Timer::periodic, to sleep_ms, oneshot_ms, periodic_ms. These functions all take an integer and interpret it as milliseconds. Replacement functions will be added that take Duration. [breaking-change]
2014-08-13std: Rename slice::Vector to SliceBrian Anderson-3/+3
This required some contortions because importing both raw::Slice and slice::Slice makes rustc crash. Since `Slice` is in the prelude, this renaming is unlikely to casue breakage. [breaking-change]
2014-08-13std: Rename various slice traits for consistencyBrian Anderson-11/+11
ImmutableVector -> ImmutableSlice ImmutableEqVector -> ImmutableEqSlice ImmutableOrdVector -> ImmutableOrdSlice MutableVector -> MutableSlice MutableVectorAllocating -> MutableSliceAllocating MutableCloneableVector -> MutableCloneableSlice MutableOrdVector -> MutableOrdSlice These are all in the prelude so most code will not break. [breaking-change]
2014-08-12libnative: process spawning should not close inherited file descriptorsIvan Petkov-1/+24
* The caller should be responsible for cleaning up file descriptors * If a caller safely creates a file descriptor (via native::io::file::open) the returned structure (FileDesc) will try to clean up the file, failing in the process and writing error messages to the screen. * This should not happen as the caller has no public interface for telling the FileDesc structure to NOT free the underlying fd. * Alternatively, if another file is opened under the same fd held by the FileDesc structure returned by native::io::file::open, it will close the wrong file upon destruction.
2014-08-08auto merge of #16336 : retep998/rust/master, r=brsonbors-4/+5
Several of the tests in `make check-fast` were failing so this fixes those tests.
2014-08-08Register new snapshot 12e0f72Niko Matsakis-3/+0
2014-08-07windows: Fix several tests on 64-bit.Peter Atashian-4/+5
Signed-off-by: Peter Atashian <retep998@gmail.com>
2014-08-07auto merge of #16220 : tshepang/rust/temp, r=steveklabnikbors-1/+1
2014-08-06auto merge of #16291 : nham/rust/byte_literals, r=alexcrichtonbors-18/+18
This replaces many instances chars being casted to u8 with byte literals.
2014-08-06auto merge of #16258 : aturon/rust/stabilize-atomics, r=alexcrichtonbors-4/+4
This commit stabilizes the `std::sync::atomics` module, renaming it to `std::sync::atomic` to match library precedent elsewhere, and tightening up behavior around incorrect memory ordering annotations. The vast majority of the module is now `stable`. However, the `AtomicOption` type has been deprecated, since it is essentially unused and is not truly a primitive atomic type. It will eventually be replaced by a higher-level abstraction like MVars. Due to deprecations, this is a: [breaking-change]
2014-08-06Use byte literals in libstdnham-18/+18
2014-08-05auto merge of #16243 : alexcrichton/rust/fix-utime-for-windows, r=brsonbors-6/+4
Apparently the units are in milliseconds, not in seconds!
2014-08-04stabilize atomics (now atomic)Aaron Turon-4/+4
This commit stabilizes the `std::sync::atomics` module, renaming it to `std::sync::atomic` to match library precedent elsewhere, and tightening up behavior around incorrect memory ordering annotations. The vast majority of the module is now `stable`. However, the `AtomicOption` type has been deprecated, since it is essentially unused and is not truly a primitive atomic type. It will eventually be replaced by a higher-level abstraction like MVars. Due to deprecations, this is a: [breaking-change]
2014-08-03doc: make the sentence make more senseTshepang Lekhonkhobe-1/+1
2014-08-02native: Fix utime() for windowsAlex Crichton-6/+4
Apparently the units are in milliseconds, not in seconds!
2014-08-01Fix misspelled comments.Joseph Crail-1/+1
2014-07-31auto merge of #15399 : kballard/rust/rewrite_local_data, r=alexcrichtonbors-4/+4
This was motivated by a desire to remove allocation in the common pattern of let old = key.replace(None) do_something(); key.replace(old); This also switched the map representation from a Vec to a TreeMap. A Vec may be reasonable if there's only a couple TLD keys, but a TreeMap provides better behavior as the number of keys increases. Like the Vec, this TreeMap implementation does not shrink the container when a value is removed. Unlike Vec, this TreeMap implementation cannot reuse an empty node for a different key. Therefore any key that has been inserted into the TLD at least once will continue to take up space in the Map until the task ends. The expectation is that the majority of keys that are inserted into TLD will be expected to have a value for most of the rest of the task's lifetime. If this assumption is wrong, there are two reasonable ways to fix this that could be implemented in the future: 1. Provide an API call to either remove a specific key from the TLD and destruct its node (e.g. `remove()`), or instead to explicitly clean up all currently-empty nodes in the map (e.g. `compact()`). This is simple, but requires the user to explicitly call it. 2. Keep track of the number of empty nodes in the map and when the map is mutated (via `replace()`), if the number of empty nodes passes some threshold, compact it automatically. Alternatively, whenever a new key is inserted that hasn't been used before, compact the map at that point. --- Benchmarks: I ran 3 benchmarks. tld_replace_none just replaces the tld key with None repeatedly. tld_replace_some replaces it with Some repeatedly. And tld_replace_none_some simulates the common behavior of replacing with None, then replacing with the previous value again (which was a Some). Old implementation: test tld_replace_none ... bench: 20 ns/iter (+/- 0) test tld_replace_none_some ... bench: 77 ns/iter (+/- 4) test tld_replace_some ... bench: 57 ns/iter (+/- 2) New implementation: test tld_replace_none ... bench: 11 ns/iter (+/- 0) test tld_replace_none_some ... bench: 23 ns/iter (+/- 0) test tld_replace_some ... bench: 12 ns/iter (+/- 0)