about summary refs log tree commit diff
path: root/src/libcollections
AgeCommit message (Collapse)AuthorLines
2014-11-26rollup merge of #19231: Gankro/ringbuf-into-iterAlex Crichton-8/+102
r? @huonw @csherratt
2014-11-26Remove special casing for some meta attributesSteven Fackler-1/+0
Descriptions and licenses are handled by Cargo now, so there's no reason to keep these attributes around.
2014-11-26auto merge of #19176 : aturon/rust/stab-iter, r=alexcrichtonbors-29/+31
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-25Make BinaryHeap's Items iterator implement DoubleEnded and ExactSizeChase Southwood-0/+17
2014-11-25/** -> ///Steve Klabnik-21/+19
This is considered good convention.
2014-11-25Fallout from stabilizationAaron Turon-29/+31
2014-11-25Deprecate MaybeOwned[Vector] in favor of CowJorge Aparicio-28/+104
2014-11-25vec: add missing out-of-memory checkDaniel Micay-0/+1
Closes #19305
2014-11-25Update documentation for from_raw_partsSteve Klabnik-8/+2
Fixes #19269.
2014-11-25auto merge of #19149 : alexcrichton/rust/issue-19091, r=aturonbors-1/+5
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-25Implement union, intersection, and difference functions for TrieSet.Chase Southwood-1/+268
2014-11-24std: Export BinarySearchResultAlex Crichton-1/+1
At the same time remove the `pub use` of the variants in favor of accessing through the enum type itself. This is a breaking change as the `Found` and `NotFound` variants must now be imported through `BinarySearchResult` instead of just `std::slice`. [breaking-change] Closes #19272
2014-11-24auto merge of #19236 : csouth3/rust/master, r=Gankrobors-3/+79
Whilst browsing the source for BinaryHeap, I saw a FIXME for implementing into_iter. I think, since the BinaryHeap is represented internally using just a Vec, just calling into_iter() on the BinaryHeap's data should be sufficient to do what we want here. If this actually isn't the right approach (e.g., I should write a struct MoveItems and appropriate implementation for BinaryHeap instead), let me know and I'll happily rework this. Both of the tests that I have added pass. This is my first contribution to Rust, so please let me know any ways I can improve this PR!
2014-11-24auto merge of #19192 : nodakai/rust/generalize-strvector, r=alexcrichtonbors-36/+75
A single impl supports all of `[T]`, `Vec<T>` and `CVec<T>`. Once `Iterable` is implemented, we will prefer it to `SlicePrelude`. But the `with_capacity()` part might become tricky.
2014-11-23Implement into_iter() for BinaryHeap.Chase Southwood-3/+79
2014-11-23Rename unwrap functions to into_innerAlex Crichton-1/+5
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-23add MoveItems to RingBuf, fixes #19085Alexis Beingessner-8/+102
2014-11-23rollup merge of #19210: petrochenkov/masterJakub Bukaj-2/+2
Now `std::hash::hash("abcd")` works.
2014-11-23rollup merge of #19204: mcpherrinm/masterJakub Bukaj-53/+53
The old name was sensible when this module was PriorityQueue but isn't anymore.
2014-11-23libcollection: generalize StrVector to AsSlice<Str>.NODA, Kai-36/+75
The impl for [T] also works as impl for slices in general. By generalizing the impl of StrVector for Vec<Str> to that for AsSlice<Str>, it becomes much more generic. Once Iterable is implemented, we will prefer it to AsSlice. But the with_capacity() part might become tricky. Signed-off-by: NODA, Kai <nodakai@gmail.com>
2014-11-23auto merge of #19157 : aturon/rust/cow-doc, r=alexcrichtonbors-3/+13
This commit makes `Cow` more usable by allowing it to be applied to unsized types (as was intended) and providing some basic `ToOwned` implementations on slice types. It also corrects the documentation for `Cow` to no longer mention `DerefMut`, and adds an example. Closes #19123
2014-11-23auto merge of #19152 : alexcrichton/rust/issue-17863, r=aturonbors-42/+80
This commit is an implementation of [RFC 240][rfc] when applied to the standard library. It primarily deprecates the entirety of `string::raw`, `vec::raw`, `slice::raw`, and `str::raw` in favor of associated functions, methods, and other free functions. The detailed renaming is: * slice::raw::buf_as_slice => slice::from_raw_buf * slice::raw::mut_buf_as_slice => slice::from_raw_mut_buf * slice::shift_ptr => deprecated with no replacement * slice::pop_ptr => deprecated with no replacement * str::raw::from_utf8 => str::from_utf8_unchecked * str::raw::c_str_to_static_slice => str::from_c_str * str::raw::slice_bytes => deprecated for slice_unchecked (slight semantic diff) * str::raw::slice_unchecked => str.slice_unchecked * string::raw::from_parts => String::from_raw_parts * string::raw::from_buf_len => String::from_raw_buf_len * string::raw::from_buf => String::from_raw_buf * string::raw::from_utf8 => String::from_utf8_unchecked * vec::raw::from_buf => Vec::from_raw_buf All previous functions exist in their `#[deprecated]` form, and the deprecation messages indicate how to migrate to the newer variants. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0240-unsafe-api-location.md [breaking-change] Closes #17863
2014-11-22std: Align `raw` modules with unsafe conventionsAlex Crichton-42/+80
This commit is an implementation of [RFC 240][rfc] when applied to the standard library. It primarily deprecates the entirety of `string::raw`, `vec::raw`, `slice::raw`, and `str::raw` in favor of associated functions, methods, and other free functions. The detailed renaming is: * slice::raw::buf_as_slice => slice::with_raw_buf * slice::raw::mut_buf_as_slice => slice::with_raw_mut_buf * slice::shift_ptr => deprecated with no replacement * slice::pop_ptr => deprecated with no replacement * str::raw::from_utf8 => str::from_utf8_unchecked * str::raw::c_str_to_static_slice => str::from_c_str * str::raw::slice_bytes => deprecated for slice_unchecked (slight semantic diff) * str::raw::slice_unchecked => str.slice_unchecked * string::raw::from_parts => String::from_raw_parts * string::raw::from_buf_len => String::from_raw_buf_len * string::raw::from_buf => String::from_raw_buf * string::raw::from_utf8 => String::from_utf8_unchecked * vec::raw::from_buf => Vec::from_raw_buf All previous functions exist in their `#[deprecated]` form, and the deprecation messages indicate how to migrate to the newer variants. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0240-unsafe-api-location.md [breaking-change] Closes #17863
2014-11-22DSTify free functions in std::hashwe-2/+2
2014-11-21Rename variables called pq to heapMatt McPherrin-53/+53
The old name was sensible when this module was PriorityQueue but isn't anymore.
2014-11-21core: Convert Char::escape_default, escape_unicode to iteratorsBrian Anderson-2/+6
[breaking-change]
2014-11-21unicode: Rename UnicodeChar::is_digit to is_numericBrian Anderson-3/+3
'Numeric' is the proper name of the unicode character class, and this frees up the word 'digit' for ascii use in libcore. Since I'm going to rename `Char::is_digit_radix` to `is_digit`, I am not leaving a deprecated method in place, because that would just cause name clashes, as both `Char` and `UnicodeChar` are in the prelude. [breaking-change]
2014-11-21auto merge of #19042 : SimonSapin/rust/generic-utf16-encoder, r=alexcrichtonbors-1/+2
This allows encoding to UTF-16 something that is not in UTF-8, e.g. a `[char]` UTF-32 string. This might help with servo/servo#4023
2014-11-21auto merge of #18908 : tbu-/rust/pr_mapinplace_fixzerosized, r=alexcrichtonbors-1/+4
2014-11-21auto merge of #18967 : aturon/rust/remove-runtime, r=alexcrichtonbors-4/+5
This PR completes the removal of the runtime system and green-threaded abstractions as part of implementing [RFC 230](https://github.com/rust-lang/rfcs/pull/230). Specifically: * It removes the `Runtime` trait, welding the scheduling infrastructure directly to native threads. * It removes `libgreen` and `libnative` entirely. * It rewrites `sync::mutex` as a trivial layer on top of native mutexes. Eventually, the two modules will be merged. * It hides the vast majority of `std::rt`. This completes the basic task of removing the runtime system (I/O and scheduling) and components that depend on it. After this lands, a follow-up PR will pull the `rustrt` crate back into `std`, turn `std::task` into `std::thread` (with API changes to go along with it), and completely cut out the remaining startup/teardown sequence. Other changes, including new [TLS](https://github.com/rust-lang/rfcs/pull/461) and synchronization are in the RFC or pre-RFC phase. Closes #17325 Closes #18687 [breaking-change] r? @alexcrichton
2014-11-20Make most of std::rt privateAaron Turon-3/+5
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-1/+0
2014-11-21auto merge of #18441 : mdinger/rust/literals, r=steveklabnikbors-3/+3
Closes #18415 This links [`std::str`](http://doc.rust-lang.org/std/str/index.html) documentation to [literals](http://doc.rust-lang.org/reference.html#literals) in the reference guide and collects examples of literals into one group at the beginning of the section. ~~The new tables are not exhaustive (some escapes were skipped) and so I try to link back to the respective sections where more detail is located.~~ The tables are are mostly exhaustive. I misunderstood some of the whitespace codes. I don't think the tables actually look that nice if that's important and I'm not sure how it could be improved. I think it does do a good job of collecting available options together. I think listing the escapes together is particularly helpful because they vary with type and are embedded in paragraphs. [EDIT] The [ascii table](http://man-ascii.com/) is here and may be useful.
2014-11-20libs: make Cow usable, improve documentationAaron Turon-3/+13
This commit makes `Cow` more usable by allowing it to be applied to unsized types (as was intended) and providing some basic `ToOwned` implementations on slice types. It also corrects the documentation for `Cow` to no longer mention `DerefMut`, and adds an example.
2014-11-20Link std::str to reference literals sectionmdinger-3/+3
2014-11-20Rename remaining Failures to PanicSubhash Bhushan-1/+1
2014-11-20Add Utf16Encoder. Generalize Utf16CodeUnits for any Iterator<char>.Simon Sapin-1/+2
This allows encoding to UTF-16 something that is not in UTF-8, e.g. a `[char]` UTF-32 string. This might help with https://github.com/servo/servo/issues/4023
2014-11-20libcore: DST-ify AsSliceAaron Turon-3/+4
This commit changes `AsSlice` to work on unsized types, and changes the `impl` for `&[T]` to `[T]`. Aside from making the trait more general, this also helps some ongoing work with method resolution changes. This is a breaking change: code that uses generics bounded by `AsSlice` will have to change. In particular, such code previously often took arguments of type `V` where `V: AsSlice<T>` by value. These should now be taken by reference: ```rust fn foo<Sized? V: AsSlice<T>>(v: &V) { .. } ``` A few std lib functions have been changed accordingly. [breaking-change]
2014-11-19Update libcollections tests to pass the new type rules. They used to return ↵Niko Matsakis-17/+17
a pointer to the value they were modifying, but this should not have been legal, since that pointer would have to outlive the closure, and the closure continues to modify the value during the execution. This return value was just passed to `black_box` so as to convince llvm that the value was live, so rather than returning a pointer, modify to just call `black_box` directly inside the fn.
2014-11-18rollup merge of #19008: alex/collections-typosJakub Bukaj-8/+8
2014-11-18rollup merge of #18911: canndrew/slice_shift_charJakub Bukaj-2/+2
`slice_shift_char` splits a `str` into it's leading `char` and the remainder of the `str`. Currently, it returns a `(Option<char>, &str)` such that: "bar".slice_shift_char() => (Some('b'), "ar") "ar".slice_shift_char() => (Some('a'), "r") "r".slice_shift_char() => (Some('r'), "") "".slice_shift_char() => (None, "") This is a little odd. Either a `str` can be split into both a head and a tail or it cannot. So the return type should be `Option<(char, &str)>`. With the current behaviour, in the case of the empty string, the `str` returned is meaningless - it is always the empty string. This PR changes `slice_shift_char` so that: "bar".slice_shift_char() => Some(('b', "ar")) "ar".slice_shift_char() => Some(('a', "r")) "r".slice_shift_char() => Some(('r', "")) "".slice_shift_char() => None
2014-11-17libcollections: generalize BTree* to use BorrowFromAaron Turon-15/+42
Generalizes the BTree-based collections to use the new BorrowFrom infrastructure for more flexible lookups and removals.
2014-11-17Fallout from deprecationAaron Turon-2/+2
This commit handles the fallout from deprecating `_with` and `_equiv` methods.
2014-11-17libcollections: use BorrowFrom in TreeSet, MapAaron Turon-17/+56
This commit generalizes methods like `get` and `remove` for `TreeMap` and `TreeSet` to use the new `std::borrow` infrastructure. [breaking-change]
2014-11-17libcore: add borrow moduleAaron Turon-1/+17
Following [the collections reform RFC](https://github.com/rust-lang/rfcs/pull/235), this commit adds a new `borrow` module to libcore. The module contains traits for borrowing data (`BorrowFrom` and `BorrowFromMut`), generalized cloning (`ToOwned`), and a clone-on-write smartpointer (`Cow`).
2014-11-17Switch to purely namespaced enumsSteven Fackler-5/+23
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-360/+360
2014-11-17change return type of slice_shift_charAndrew Cann-2/+2
`slice_shift_char` splits a `str` into it's leading `char` and the remainder of the `str`. Currently, it returns a `(Option<char>, &str)` such that: "bar".slice_shift_char() => (Some('b'), "ar") "ar".slice_shift_char() => (Some('a'), "r") "r".slice_shift_char() => (Some('r'), "") "".slice_shift_char() => (None, "") This is a little odd. Either a `str` can be split into both a head and a tail or it cannot. So the return type should be `Option<(char, &str)>`. With the current behaviour, in the case of the empty string, the `str` returned is meaningless - it is always the empty string. This commit changes slice_shift_char so that: "bar".slice_shift_char() => Some(('b', "ar")) "ar".slice_shift_char() => Some(('a', "r")) "r".slice_shift_char() => Some(('r', "")) "".slice_shift_char() => None [breaking-change]
2014-11-16auto merge of #18747 : csherratt/rust/ringbuf-remove-option, r=huonwbors-198/+513
Fix for task in Metabug #18009 (Rebased version of https://github.com/rust-lang/rust/pull/18170) This changes much of about how RingBuf functions. `lo`, `nelts` are replaced by a more traditional `head` and`tail`. The `Vec<Option<T>>` is replaced by a bare pointer that is managed by the `RingBuf` itself. This also expects the ring buffer to always be size that is a power of 2. This change also includes a number of new tests to cover the some areas that could be of concern with manual memory management. The benchmarks have been reworked since the old ones were benchmarking of the Ring buffers growth rather then the actual test. The unit test suite have been expanded, and exposed some bugs in `fn get()` and `fn get_mut()` ## Benchmark **Before:** ``` test ring_buf::tests::bench_grow_1025 ... bench: 8919 ns/iter (+/- 87) test ring_buf::tests::bench_iter_1000 ... bench: 924 ns/iter (+/- 28) test ring_buf::tests::bench_mut_iter_1000 ... bench: 918 ns/iter (+/- 6) test ring_buf::tests::bench_new ... bench: 15 ns/iter (+/- 0) test ring_buf::tests::bench_pop_100 ... bench: 294 ns/iter (+/- 9) test ring_buf::tests::bench_pop_front_100 ... bench: 948 ns/iter (+/- 32) test ring_buf::tests::bench_push_back_100 ... bench: 291 ns/iter (+/- 16) test ring_buf::tests::bench_push_front_100 ... bench: 311 ns/iter (+/- 27 ``` **After:** ``` test ring_buf::tests::bench_grow_1025 ... bench: 2209 ns/iter (+/- 169) test ring_buf::tests::bench_iter_1000 ... bench: 534 ns/iter (+/- 27) test ring_buf::tests::bench_mut_iter_1000 ... bench: 515 ns/iter (+/- 28) test ring_buf::tests::bench_new ... bench: 11 ns/iter (+/- 0) test ring_buf::tests::bench_pop_100 ... bench: 170 ns/iter (+/- 5) test ring_buf::tests::bench_pop_front_100 ... bench: 171 ns/iter (+/- 11) test ring_buf::tests::bench_push_back_100 ... bench: 172 ns/iter (+/- 13) test ring_buf::tests::bench_push_front_100 ... bench: 158 ns/iter (+/- 12) ```
2014-11-16Fixed several typos in libcollectionsAlex Gaynor-8/+8