about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-12-19 04:20:11 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-12-19 04:20:11 +0300
commite3da2a90033d233bf6d77e3c725880c12cfc8728 (patch)
tree870fdabe7ae4b8e3858cf6701ea87cbf1ddb8e9a /src/libsyntax
parent29ea4eef9fa6e36f40bc1f31eb1e56bf5941ee72 (diff)
Improve OwnedSlice and use it in HIR
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ptr.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs
index 1be0b08086d..0504c313c91 100644
--- a/src/libsyntax/ptr.rs
+++ b/src/libsyntax/ptr.rs
@@ -130,6 +130,10 @@ impl<T:fmt::Debug> fmt::Debug for P<[T]> {
 }
 
 impl<T> P<[T]> {
+    pub fn new() -> P<[T]> {
+        P::empty()
+    }
+
     pub fn empty() -> P<[T]> {
         P { ptr: Default::default() }
     }
@@ -177,12 +181,33 @@ impl<T: Clone> Clone for P<[T]> {
     }
 }
 
+impl<T> From<Vec<T>> for P<[T]> {
+    fn from(v: Vec<T>) -> Self {
+        P::from_vec(v)
+    }
+}
+
+impl<T> Into<Vec<T>> for P<[T]> {
+    fn into(self) -> Vec<T> {
+        self.into_vec()
+    }
+}
+
 impl<T> FromIterator<T> for P<[T]> {
     fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> P<[T]> {
         P::from_vec(iter.into_iter().collect())
     }
 }
 
+impl<T> IntoIterator for P<[T]> {
+    type Item = T;
+    type IntoIter = vec::IntoIter<T>;
+
+    fn into_iter(self) -> Self::IntoIter {
+        self.into_vec().into_iter()
+    }
+}
+
 impl<'a, T> IntoIterator for &'a P<[T]> {
     type Item = &'a T;
     type IntoIter = slice::Iter<'a, T>;