From 21ac985af44f4e2470ef6f4c0eb4d72daf5a6497 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 30 Oct 2014 13:43:24 -0700 Subject: 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 --- src/libsyntax/owned_slice.rs | 8 ++++---- src/libsyntax/util/small_vector.rs | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/owned_slice.rs b/src/libsyntax/owned_slice.rs index 4f09b34557c..f622e2d6112 100644 --- a/src/libsyntax/owned_slice.rs +++ b/src/libsyntax/owned_slice.rs @@ -112,6 +112,10 @@ impl OwnedSlice { pub fn map(&self, f: |&T| -> U) -> OwnedSlice { self.iter().map(f).collect() } + + pub fn len(&self) -> uint { self.len } + + pub fn is_empty(&self) -> bool { self.len == 0 } } impl Default for OwnedSlice { @@ -140,10 +144,6 @@ impl PartialEq for OwnedSlice { impl Eq for OwnedSlice {} -impl Collection for OwnedSlice { - fn len(&self) -> uint { self.len } -} - impl FromIterator for OwnedSlice { fn from_iter>(mut iter: I) -> OwnedSlice { OwnedSlice::from_vec(iter.collect()) diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index 422c2d5c75b..56ee6c7b915 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -25,16 +25,6 @@ enum SmallVectorRepr { Many(Vec), } -impl Collection for SmallVector { - fn len(&self) -> uint { - match self.repr { - Zero => 0, - One(..) => 1, - Many(ref vals) => vals.len() - } - } -} - impl FromIterator for SmallVector { fn from_iter>(iter: I) -> SmallVector { let mut v = SmallVector::zero(); @@ -131,6 +121,16 @@ impl SmallVector { }; MoveItems { repr: repr } } + + pub fn len(&self) -> uint { + match self.repr { + Zero => 0, + One(..) => 1, + Many(ref vals) => vals.len() + } + } + + pub fn is_empty(&self) -> bool { self.len() == 0 } } pub struct MoveItems { -- cgit 1.4.1-3-g733a5