diff options
Diffstat (limited to 'src/libsyntax/util')
| -rw-r--r-- | src/libsyntax/util/small_vector.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index 792673e3298..693407b854f 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -9,6 +9,7 @@ // except according to those terms. use std::mem; +use std::slice; use std::vec; /// A vector type optimized for cases where the size is almost always 0 or 1 @@ -61,6 +62,14 @@ impl<T> SmallVector<T> { SmallVector { repr: Many(vs) } } + pub fn as_slice<'a>(&'a self) -> &'a [T] { + match self.repr { + Zero => &[], + One(ref v) => slice::ref_slice(v), + Many(ref vs) => vs.as_slice() + } + } + pub fn push(&mut self, v: T) { match self.repr { Zero => self.repr = One(v), |
