about summary refs log tree commit diff
path: root/src/libsyntax/util
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-04-15 18:05:38 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-04-15 19:17:44 -0700
commit83351fa02e08caa8fb8017254cc6e7c99fc65d2b (patch)
treeba1d32ccf6dde845558040cd60ab3d2b177fb26a /src/libsyntax/util
parent10f94e3fe5859fe7fc001cf26f4fa401d9a2ee2e (diff)
downloadrust-83351fa02e08caa8fb8017254cc6e7c99fc65d2b.tar.gz
rust-83351fa02e08caa8fb8017254cc6e7c99fc65d2b.zip
Remove usage of private enum variants
This replaces all uses of private enum variants with a struct that has
one private field pointing at a private enum.

RFC: 0006-remove-priv
Diffstat (limited to 'src/libsyntax/util')
-rw-r--r--src/libsyntax/util/small_vector.rs59
1 files changed, 34 insertions, 25 deletions
diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs
index 1dcebd7a016..792673e3298 100644
--- a/src/libsyntax/util/small_vector.rs
+++ b/src/libsyntax/util/small_vector.rs
@@ -12,15 +12,19 @@ use std::mem;
 use std::vec;
 
 /// A vector type optimized for cases where the size is almost always 0 or 1
-pub enum SmallVector<T> {
-    priv Zero,
-    priv One(T),
-    priv Many(Vec<T> ),
+pub struct SmallVector<T> {
+    repr: SmallVectorRepr<T>,
+}
+
+enum SmallVectorRepr<T> {
+    Zero,
+    One(T),
+    Many(Vec<T> ),
 }
 
 impl<T> Container for SmallVector<T> {
     fn len(&self) -> uint {
-        match *self {
+        match self.repr {
             Zero => 0,
             One(..) => 1,
             Many(ref vals) => vals.len()
@@ -30,7 +34,7 @@ impl<T> Container for SmallVector<T> {
 
 impl<T> FromIterator<T> for SmallVector<T> {
     fn from_iter<I: Iterator<T>>(iter: I) -> SmallVector<T> {
-        let mut v = Zero;
+        let mut v = SmallVector::zero();
         v.extend(iter);
         v
     }
@@ -46,24 +50,24 @@ impl<T> Extendable<T> for SmallVector<T> {
 
 impl<T> SmallVector<T> {
     pub fn zero() -> SmallVector<T> {
-        Zero
+        SmallVector { repr: Zero }
     }
 
     pub fn one(v: T) -> SmallVector<T> {
-        One(v)
+        SmallVector { repr: One(v) }
     }
 
-    pub fn many(vs: Vec<T> ) -> SmallVector<T> {
-        Many(vs)
+    pub fn many(vs: Vec<T>) -> SmallVector<T> {
+        SmallVector { repr: Many(vs) }
     }
 
     pub fn push(&mut self, v: T) {
-        match *self {
-            Zero => *self = One(v),
+        match self.repr {
+            Zero => self.repr = One(v),
             One(..) => {
-                let one = mem::replace(self, Zero);
+                let one = mem::replace(&mut self.repr, Zero);
                 match one {
-                    One(v1) => mem::replace(self, Many(vec!(v1, v))),
+                    One(v1) => mem::replace(&mut self.repr, Many(vec!(v1, v))),
                     _ => unreachable!()
                 };
             }
@@ -78,7 +82,7 @@ impl<T> SmallVector<T> {
     }
 
     pub fn get<'a>(&'a self, idx: uint) -> &'a T {
-        match *self {
+        match self.repr {
             One(ref v) if idx == 0 => v,
             Many(ref vs) => vs.get(idx),
             _ => fail!("out of bounds access")
@@ -86,7 +90,7 @@ impl<T> SmallVector<T> {
     }
 
     pub fn expect_one(self, err: &'static str) -> T {
-        match self {
+        match self.repr {
             One(v) => v,
             Many(v) => {
                 if v.len() == 1 {
@@ -100,27 +104,32 @@ impl<T> SmallVector<T> {
     }
 
     pub fn move_iter(self) -> MoveItems<T> {
-        match self {
+        let repr = match self.repr {
             Zero => ZeroIterator,
             One(v) => OneIterator(v),
             Many(vs) => ManyIterator(vs.move_iter())
-        }
+        };
+        MoveItems { repr: repr }
     }
 }
 
-pub enum MoveItems<T> {
-    priv ZeroIterator,
-    priv OneIterator(T),
-    priv ManyIterator(vec::MoveItems<T>),
+pub struct MoveItems<T> {
+    repr: MoveItemsRepr<T>,
+}
+
+enum MoveItemsRepr<T> {
+    ZeroIterator,
+    OneIterator(T),
+    ManyIterator(vec::MoveItems<T>),
 }
 
 impl<T> Iterator<T> for MoveItems<T> {
     fn next(&mut self) -> Option<T> {
-        match *self {
+        match self.repr {
             ZeroIterator => None,
             OneIterator(..) => {
                 let mut replacement = ZeroIterator;
-                mem::swap(self, &mut replacement);
+                mem::swap(&mut self.repr, &mut replacement);
                 match replacement {
                     OneIterator(v) => Some(v),
                     _ => unreachable!()
@@ -131,7 +140,7 @@ impl<T> Iterator<T> for MoveItems<T> {
     }
 
     fn size_hint(&self) -> (uint, Option<uint>) {
-        match *self {
+        match self.repr {
             ZeroIterator => (0, Some(0)),
             OneIterator(..) => (1, Some(1)),
             ManyIterator(ref inner) => inner.size_hint()