summary refs log tree commit diff
path: root/src/libcore/slice.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-10-30 13:43:24 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-11-01 11:37:04 -0700
commit21ac985af44f4e2470ef6f4c0eb4d72daf5a6497 (patch)
treea120c184188926cd154b40f9da77ad8a6a455c1b /src/libcore/slice.rs
parent1442235d3feab4c5ca3f55e2b3345583f640a17e (diff)
downloadrust-21ac985af44f4e2470ef6f4c0eb4d72daf5a6497.tar.gz
rust-21ac985af44f4e2470ef6f4c0eb4d72daf5a6497.zip
collections: Remove all collections traits
As part of the collections reform RFC, this commit removes all collections
traits in favor of inherent methods on collections themselves. All methods
should continue to be available on all collections.

This is a breaking change with all of the collections traits being removed and
no longer being in the prelude. In order to update old code you should move the
trait implementations to inherent implementations directly on the type itself.

Note that some traits had default methods which will also need to be implemented
to maintain backwards compatibility.

[breaking-change]
cc #18424
Diffstat (limited to 'src/libcore/slice.rs')
-rw-r--r--src/libcore/slice.rs46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs
index dd51534d319..317a6e224bc 100644
--- a/src/libcore/slice.rs
+++ b/src/libcore/slice.rs
@@ -36,7 +36,6 @@
 
 use mem::transmute;
 use clone::Clone;
-use collections::Collection;
 use cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering, Less, Equal, Greater, Equiv};
 use cmp;
 use default::Default;
@@ -234,6 +233,29 @@ pub trait ImmutableSlice<T> for Sized? {
     /// ```
     #[unstable = "waiting on unboxed closures"]
     fn binary_search(&self, f: |&T| -> Ordering) -> BinarySearchResult;
+
+    /// Return the number of elements in the slice
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// let a = [1i, 2, 3];
+    /// assert_eq!(a.len(), 3);
+    /// ```
+    #[experimental = "not triaged yet"]
+    fn len(&self) -> uint;
+
+    /// Returns true if the slice has a length of 0
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// let a = [1i, 2, 3];
+    /// assert!(!a.is_empty());
+    /// ```
+    #[inline]
+    #[experimental = "not triaged yet"]
+    fn is_empty(&self) -> bool { self.len() == 0 }
 }
 
 #[unstable]
@@ -372,6 +394,9 @@ impl<T> ImmutableSlice<T> for [T] {
         }
         return NotFound(base);
     }
+
+    #[inline]
+    fn len(&self) -> uint { self.repr().len }
 }
 
 
@@ -886,24 +911,6 @@ impl<'a,T> AsSlice<T> for &'a [T] {
     fn as_slice<'a>(&'a self) -> &'a [T] { *self }
 }
 
-#[experimental = "trait is experimental"]
-impl<'a, T> Collection for &'a [T] {
-    /// Returns the length of a slice.
-    #[inline]
-    fn len(&self) -> uint {
-        self.repr().len
-    }
-}
-
-#[experimental = "trait is experimental"]
-impl<'a, T> Collection for &'a mut [T] {
-    /// Returns the length of a slice.
-    #[inline]
-    fn len(&self) -> uint {
-        self.repr().len
-    }
-}
-
 #[unstable = "waiting for DST"]
 impl<'a, T> Default for &'a [T] {
     fn default() -> &'a [T] { &[] }
@@ -1508,7 +1515,6 @@ pub mod raw {
 /// Operations on `[u8]`.
 #[experimental = "needs review"]
 pub mod bytes {
-    use collections::Collection;
     use kinds::Sized;
     use ptr;
     use slice::{ImmutableSlice, MutableSlice};