]> git.lizzy.rs Git - rust.git/blobdiff - src/libcore/slice/mod.rs
Rollup merge of #44562 - eddyb:ugh-rustdoc, r=nikomatsakis
[rust.git] / src / libcore / slice / mod.rs
index 0509936153c39c5d244ca0be69c8991eb1d2ceb9..dacc014955a902f3d79a32f63c71f9ee57a7cb94 100644 (file)
@@ -35,7 +35,6 @@
 // * The `raw` and `bytes` submodules.
 // * Boilerplate trait implementations.
 
-use borrow::Borrow;
 use cmp::Ordering::{self, Less, Equal, Greater};
 use cmp;
 use fmt;
@@ -122,19 +121,17 @@ unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
     fn as_ptr(&self) -> *const Self::Item;
 
     #[stable(feature = "core", since = "1.6.0")]
-    fn binary_search<Q: ?Sized>(&self, x: &Q) -> Result<usize, usize>
-        where Self::Item: Borrow<Q>,
-              Q: Ord;
+    fn binary_search(&self, x: &Self::Item) -> Result<usize, usize>
+        where Self::Item: Ord;
 
     #[stable(feature = "core", since = "1.6.0")]
     fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
         where F: FnMut(&'a Self::Item) -> Ordering;
 
     #[stable(feature = "slice_binary_search_by_key", since = "1.10.0")]
-    fn binary_search_by_key<'a, B, F, Q: ?Sized>(&'a self, b: &Q, f: F) -> Result<usize, usize>
+    fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<usize, usize>
         where F: FnMut(&'a Self::Item) -> B,
-              B: Borrow<Q>,
-              Q: Ord;
+              B: Ord;
 
     #[stable(feature = "core", since = "1.6.0")]
     fn len(&self) -> usize;
@@ -212,6 +209,9 @@ unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output
     #[stable(feature = "copy_from_slice", since = "1.9.0")]
     fn copy_from_slice(&mut self, src: &[Self::Item]) where Self::Item: Copy;
 
+    #[unstable(feature = "swap_with_slice", issue = "44030")]
+    fn swap_with_slice(&mut self, src: &mut [Self::Item]);
+
     #[stable(feature = "sort_unstable", since = "1.20.0")]
     fn sort_unstable(&mut self)
         where Self::Item: Ord;
@@ -632,11 +632,10 @@ fn ends_with(&self, needle: &[T]) -> bool where T: PartialEq {
         m >= n && needle == &self[m-n..]
     }
 
-    fn binary_search<Q: ?Sized>(&self, x: &Q) -> Result<usize, usize>
-        where T: Borrow<Q>,
-              Q: Ord
+    fn binary_search(&self, x: &T) -> Result<usize, usize>
+        where T: Ord
     {
-        self.binary_search_by(|p| p.borrow().cmp(x))
+        self.binary_search_by(|p| p.cmp(x))
     }
 
     fn rotate(&mut self, mid: usize) {
@@ -674,12 +673,21 @@ fn copy_from_slice(&mut self, src: &[T]) where T: Copy {
     }
 
     #[inline]
-    fn binary_search_by_key<'a, B, F, Q: ?Sized>(&'a self, b: &Q, mut f: F) -> Result<usize, usize>
+    fn swap_with_slice(&mut self, src: &mut [T]) {
+        assert!(self.len() == src.len(),
+                "destination and source slices have different lengths");
+        unsafe {
+            ptr::swap_nonoverlapping(
+                self.as_mut_ptr(), src.as_mut_ptr(), self.len());
+        }
+    }
+
+    #[inline]
+    fn binary_search_by_key<'a, B, F>(&'a self, b: &B, mut f: F) -> Result<usize, usize>
         where F: FnMut(&'a Self::Item) -> B,
-              B: Borrow<Q>,
-              Q: Ord
+              B: Ord
     {
-        self.binary_search_by(|k| f(k).borrow().cmp(b))
+        self.binary_search_by(|k| f(k).cmp(b))
     }
 
     #[inline]