diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-12-02 17:31:49 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-12-05 15:09:44 -0800 |
| commit | 464cdff102993ff1900eebbf65209e0a3c0be0d5 (patch) | |
| tree | 12910564caf0946c19be1ac48355210a49b7afee /src/libcollections | |
| parent | ac0e84522437331f9a06d04a5842acf0234cc86e (diff) | |
| download | rust-464cdff102993ff1900eebbf65209e0a3c0be0d5.tar.gz rust-464cdff102993ff1900eebbf65209e0a3c0be0d5.zip | |
std: Stabilize APIs for the 1.6 release
This commit is the standard API stabilization commit for the 1.6 release cycle. The list of issues and APIs below have all been through their cycle-long FCP and the libs team decisions are listed below Stabilized APIs * `Read::read_exact` * `ErrorKind::UnexpectedEof` (renamed from `UnexpectedEOF`) * libcore -- this was a bit of a nuanced stabilization, the crate itself is now marked as `#[stable]` and the methods appearing via traits for primitives like `char` and `str` are now also marked as stable. Note that the extension traits themeselves are marked as unstable as they're imported via the prelude. The `try!` macro was also moved from the standard library into libcore to have the same interface. Otherwise the functions all have copied stability from the standard library now. * The `#![no_std]` attribute * `fs::DirBuilder` * `fs::DirBuilder::new` * `fs::DirBuilder::recursive` * `fs::DirBuilder::create` * `os::unix::fs::DirBuilderExt` * `os::unix::fs::DirBuilderExt::mode` * `vec::Drain` * `vec::Vec::drain` * `string::Drain` * `string::String::drain` * `vec_deque::Drain` * `vec_deque::VecDeque::drain` * `collections::hash_map::Drain` * `collections::hash_map::HashMap::drain` * `collections::hash_set::Drain` * `collections::hash_set::HashSet::drain` * `collections::binary_heap::Drain` * `collections::binary_heap::BinaryHeap::drain` * `Vec::extend_from_slice` (renamed from `push_all`) * `Mutex::get_mut` * `Mutex::into_inner` * `RwLock::get_mut` * `RwLock::into_inner` * `Iterator::min_by_key` (renamed from `min_by`) * `Iterator::max_by_key` (renamed from `max_by`) Deprecated APIs * `ErrorKind::UnexpectedEOF` (renamed to `UnexpectedEof`) * `OsString::from_bytes` * `OsStr::to_cstring` * `OsStr::to_bytes` * `fs::walk_dir` and `fs::WalkDir` * `path::Components::peek` * `slice::bytes::MutableByteVector` * `slice::bytes::copy_memory` * `Vec::push_all` (renamed to `extend_from_slice`) * `Duration::span` * `IpAddr` * `SocketAddr::ip` * `Read::tee` * `io::Tee` * `Write::broadcast` * `io::Broadcast` * `Iterator::min_by` (renamed to `min_by_key`) * `Iterator::max_by` (renamed to `max_by_key`) * `net::lookup_addr` New APIs (still unstable) * `<[T]>::sort_by_key` (added to mirror `min_by_key`) Closes #27585 Closes #27704 Closes #27707 Closes #27710 Closes #27711 Closes #27727 Closes #27740 Closes #27744 Closes #27799 Closes #27801 cc #27801 (doesn't close as `Chars` is still unstable) Closes #28968
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/binary_heap.rs | 7 | ||||
| -rw-r--r-- | src/libcollections/lib.rs | 5 | ||||
| -rw-r--r-- | src/libcollections/slice.rs | 33 | ||||
| -rw-r--r-- | src/libcollections/string.rs | 28 | ||||
| -rw-r--r-- | src/libcollections/vec.rs | 54 | ||||
| -rw-r--r-- | src/libcollections/vec_deque.rs | 14 |
6 files changed, 95 insertions, 46 deletions
diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 06ff8581b5e..b8ca48ac75d 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -581,10 +581,7 @@ impl<T: Ord> BinaryHeap<T> { /// /// The elements are removed in arbitrary order. #[inline] - #[unstable(feature = "drain", - reason = "matches collection reform specification, \ - waiting for dust to settle", - issue = "27711")] + #[stable(feature = "drain", since = "1.6.0")] pub fn drain(&mut self) -> Drain<T> { Drain { iter: self.data.drain(..) } } @@ -738,7 +735,7 @@ impl<T> DoubleEndedIterator for IntoIter<T> { impl<T> ExactSizeIterator for IntoIter<T> {} /// An iterator that drains a `BinaryHeap`. -#[unstable(feature = "drain", reason = "recent addition", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] pub struct Drain<'a, T: 'a> { iter: vec::Drain<'a, T>, } diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index b39c3cd4485..a7797d4b0d0 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -43,8 +43,6 @@ #![feature(box_patterns)] #![feature(box_syntax)] #![feature(core_intrinsics)] -#![feature(core_slice_ext)] -#![feature(core_str_ext)] #![feature(fmt_internals)] #![feature(fmt_radix)] #![feature(heap_api)] @@ -68,9 +66,10 @@ #![feature(unsafe_no_drop_flag, filling_drop)] #![feature(decode_utf16)] #![feature(drop_in_place)] +#![feature(clone_from_slice)] #![cfg_attr(test, feature(clone_from_slice, rand, test))] -#![feature(no_std)] +#![cfg_attr(stage0, feature(no_std))] #![no_std] extern crate rustc_unicode; diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 82cadd7ac0d..6342ae5c816 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -160,7 +160,7 @@ mod hack { where T: Clone { let mut vector = Vec::with_capacity(s.len()); - vector.push_all(s); + vector.extend_from_slice(s); vector } } @@ -777,6 +777,33 @@ impl<T> [T] { self.sort_by(|a, b| a.cmp(b)) } + /// Sorts the slice, in place, using `key` to extract a key by which to + /// order the sort by. + /// + /// This sort is `O(n log n)` worst-case and stable, but allocates + /// approximately `2 * n`, where `n` is the length of `self`. + /// + /// This is a stable sort. + /// + /// # Examples + /// + /// ```rust + /// #![feature(slice_sort_by_key)] + /// + /// let mut v = [-5i32, 4, 1, -3, 2]; + /// + /// v.sort_by_key(|k| k.abs()); + /// assert!(v == [1, 2, -3, 4, -5]); + /// ``` + #[unstable(feature = "slice_sort_by_key", reason = "recently added", + issue = "27724")] + #[inline] + pub fn sort_by_key<B, F>(&mut self, mut f: F) + where F: FnMut(&T) -> B, B: Ord + { + self.sort_by(|a, b| f(a).cmp(&f(b))) + } + /// Sorts the slice, in place, using `compare` to compare /// elements. /// @@ -906,7 +933,7 @@ impl<T: Clone, V: Borrow<[T]>> SliceConcatExt<T> for [V] { let size = self.iter().fold(0, |acc, v| acc + v.borrow().len()); let mut result = Vec::with_capacity(size); for v in self { - result.push_all(v.borrow()) + result.extend_from_slice(v.borrow()) } result } @@ -921,7 +948,7 @@ impl<T: Clone, V: Borrow<[T]>> SliceConcatExt<T> for [V] { } else { result.push(sep.clone()) } - result.push_all(v.borrow()) + result.extend_from_slice(v.borrow()) } result } diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index c5e0af3d800..a3c69182934 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -482,7 +482,7 @@ impl String { let mut res = String::with_capacity(total); if i > 0 { - unsafe { res.as_mut_vec().push_all(&v[..i]) }; + unsafe { res.as_mut_vec().extend_from_slice(&v[..i]) }; } // subseqidx is the index of the first byte of the subsequence we're @@ -498,10 +498,10 @@ impl String { macro_rules! error { () => ({ unsafe { if subseqidx != i_ { - res.as_mut_vec().push_all(&v[subseqidx..i_]); + res.as_mut_vec().extend_from_slice(&v[subseqidx..i_]); } subseqidx = i; - res.as_mut_vec().push_all(REPLACEMENT); + res.as_mut_vec().extend_from_slice(REPLACEMENT); } })} @@ -566,7 +566,7 @@ impl String { } } if subseqidx < total { - unsafe { res.as_mut_vec().push_all(&v[subseqidx..total]) }; + unsafe { res.as_mut_vec().extend_from_slice(&v[subseqidx..total]) }; } Cow::Owned(res) } @@ -699,7 +699,7 @@ impl String { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn push_str(&mut self, string: &str) { - self.vec.push_all(string.as_bytes()) + self.vec.extend_from_slice(string.as_bytes()) } /// Returns the number of bytes that this string buffer can hold without @@ -1026,8 +1026,6 @@ impl String { /// # Examples /// /// ``` - /// #![feature(drain)] - /// /// let mut s = String::from("α is alpha, β is beta"); /// let beta_offset = s.find('β').unwrap_or(s.len()); /// @@ -1040,9 +1038,7 @@ impl String { /// s.drain(..); /// assert_eq!(s, ""); /// ``` - #[unstable(feature = "drain", - reason = "recently added, matches RFC", - issue = "27711")] + #[stable(feature = "drain", since = "1.6.0")] pub fn drain<R>(&mut self, range: R) -> Drain where R: RangeArgument<usize> { @@ -1600,7 +1596,7 @@ impl fmt::Write for String { } /// A draining iterator for `String`. -#[unstable(feature = "drain", reason = "recently added", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] pub struct Drain<'a> { /// Will be used as &'a mut String in the destructor string: *mut String, @@ -1612,12 +1608,12 @@ pub struct Drain<'a> { iter: Chars<'a>, } -#[unstable(feature = "drain", reason = "recently added", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] unsafe impl<'a> Sync for Drain<'a> {} -#[unstable(feature = "drain", reason = "recently added", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] unsafe impl<'a> Send for Drain<'a> {} -#[unstable(feature = "drain", reason = "recently added", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] impl<'a> Drop for Drain<'a> { fn drop(&mut self) { unsafe { @@ -1631,7 +1627,7 @@ impl<'a> Drop for Drain<'a> { } } -#[unstable(feature = "drain", reason = "recently added", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] impl<'a> Iterator for Drain<'a> { type Item = char; @@ -1645,7 +1641,7 @@ impl<'a> Iterator for Drain<'a> { } } -#[unstable(feature = "drain", reason = "recently added", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] impl<'a> DoubleEndedIterator for Drain<'a> { #[inline] fn next_back(&mut self) -> Option<char> { diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 8c1f98bbd07..89b1b99cfa3 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -739,17 +739,13 @@ impl<T> Vec<T> { /// # Examples /// /// ``` - /// #![feature(drain)] - /// /// // Draining using `..` clears the whole vector. /// let mut v = vec![1, 2, 3]; /// let u: Vec<_> = v.drain(..).collect(); /// assert_eq!(v, &[]); /// assert_eq!(u, &[1, 2, 3]); /// ``` - #[unstable(feature = "drain", - reason = "recently added, matches RFC", - issue = "27711")] + #[stable(feature = "drain", since = "1.6.0")] pub fn drain<R>(&mut self, range: R) -> Drain<T> where R: RangeArgument<usize> { @@ -933,6 +929,7 @@ impl<T: Clone> Vec<T> { /// /// ``` /// #![feature(vec_push_all)] + /// #![allow(deprecated)] /// /// let mut vec = vec![1]; /// vec.push_all(&[2, 3, 4]); @@ -942,7 +939,31 @@ impl<T: Clone> Vec<T> { #[unstable(feature = "vec_push_all", reason = "likely to be replaced by a more optimized extend", issue = "27744")] + #[rustc_deprecated(reason = "renamed to extend_from_slice", + since = "1.6.0")] pub fn push_all(&mut self, other: &[T]) { + self.extend_from_slice(other) + } + + /// Appends all elements in a slice to the `Vec`. + /// + /// Iterates over the slice `other`, clones each element, and then appends + /// it to this `Vec`. The `other` vector is traversed in-order. + /// + /// Note that this function is same as `extend` except that it is + /// specialized to work with slices instead. If and when Rust gets + /// specialization this function will likely be deprecated (but still + /// available). + /// + /// # Examples + /// + /// ``` + /// let mut vec = vec![1]; + /// vec.extend_from_slice(&[2, 3, 4]); + /// assert_eq!(vec, [1, 2, 3, 4]); + /// ``` + #[stable(feature = "vec_extend_from_slice", since = "1.6.0")] + pub fn extend_from_slice(&mut self, other: &[T]) { self.reserve(other.len()); for i in 0..other.len() { @@ -1103,7 +1124,7 @@ impl<T: Clone> Clone for Vec<T> { // self.len <= other.len due to the truncate above, so the // slice here is always in-bounds. - self.push_all(&other[len..]); + self.extend_from_slice(&other[len..]); } } @@ -1350,6 +1371,21 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> { } } +macro_rules! __impl_slice_eq1 { + ($Lhs: ty, $Rhs: ty) => { + __impl_slice_eq1! { $Lhs, $Rhs, Sized } + }; + ($Lhs: ty, $Rhs: ty, $Bound: ident) => { + #[stable(feature = "rust1", since = "1.0.0")] + impl<'a, 'b, A: $Bound, B> PartialEq<$Rhs> for $Lhs where A: PartialEq<B> { + #[inline] + fn eq(&self, other: &$Rhs) -> bool { self[..] == other[..] } + #[inline] + fn ne(&self, other: &$Rhs) -> bool { self[..] != other[..] } + } + } +} + __impl_slice_eq1! { Vec<A>, Vec<B> } __impl_slice_eq1! { Vec<A>, &'b [B] } __impl_slice_eq1! { Vec<A>, &'b mut [B] } @@ -1605,7 +1641,7 @@ impl<T> Drop for IntoIter<T> { } /// A draining iterator for `Vec<T>`. -#[unstable(feature = "drain", reason = "recently added", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] pub struct Drain<'a, T: 'a> { /// Index of tail to preserve tail_start: usize, @@ -1616,9 +1652,9 @@ pub struct Drain<'a, T: 'a> { vec: *mut Vec<T>, } -#[unstable(feature = "drain", reason = "recently added", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] unsafe impl<'a, T: Sync> Sync for Drain<'a, T> {} -#[unstable(feature = "drain", reason = "recently added", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] unsafe impl<'a, T: Send> Send for Drain<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs index 26b9944f062..53597f566b8 100644 --- a/src/libcollections/vec_deque.rs +++ b/src/libcollections/vec_deque.rs @@ -778,8 +778,6 @@ impl<T> VecDeque<T> { /// # Examples /// /// ``` - /// #![feature(drain)] - /// /// use std::collections::VecDeque; /// /// // draining using `..` clears the whole deque. @@ -789,9 +787,7 @@ impl<T> VecDeque<T> { /// assert!(v.is_empty()); /// ``` #[inline] - #[unstable(feature = "drain", - reason = "matches collection reform specification, waiting for dust to settle", - issue = "27711")] + #[stable(feature = "drain", since = "1.6.0")] pub fn drain<R>(&mut self, range: R) -> Drain<T> where R: RangeArgument<usize> { @@ -1893,9 +1889,7 @@ impl<T> DoubleEndedIterator for IntoIter<T> { impl<T> ExactSizeIterator for IntoIter<T> {} /// A draining VecDeque iterator -#[unstable(feature = "drain", - reason = "matches collection reform specification, waiting for dust to settle", - issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] pub struct Drain<'a, T: 'a> { after_tail: usize, after_head: usize, @@ -1903,9 +1897,9 @@ pub struct Drain<'a, T: 'a> { deque: *mut VecDeque<T>, } -#[unstable(feature = "drain", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] unsafe impl<'a, T: Sync> Sync for Drain<'a, T> {} -#[unstable(feature = "drain", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] unsafe impl<'a, T: Send> Send for Drain<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] |
