about summary refs log tree commit diff
path: root/src/libstd/path/mod.rs
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2014-04-12 20:42:17 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2014-04-12 22:50:56 +1000
commit28e3340a078bfb53fd621900fb17d42d6e718526 (patch)
treebd66d5579ac9e4d3a3e37085c8228fdd337322de /src/libstd/path/mod.rs
parentecc774f788ca3880ce76e4b87ac0d21a3a16d3ae (diff)
downloadrust-28e3340a078bfb53fd621900fb17d42d6e718526.tar.gz
rust-28e3340a078bfb53fd621900fb17d42d6e718526.zip
std: migrate path::unix to using Vec internally.
Diffstat (limited to 'src/libstd/path/mod.rs')
-rw-r--r--src/libstd/path/mod.rs35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs
index 660f92d8f7b..72cbdccddc0 100644
--- a/src/libstd/path/mod.rs
+++ b/src/libstd/path/mod.rs
@@ -70,10 +70,10 @@ use fmt;
 use iter::Iterator;
 use option::{Option, None, Some};
 use str;
-use str::{MaybeOwned, OwnedStr, Str, StrSlice, from_utf8_lossy};
-use slice;
-use slice::{CloneableVector, OwnedCloneableVector, OwnedVector, Vector};
+use str::{MaybeOwned, Str, StrSlice, from_utf8_lossy};
+use slice::{OwnedCloneableVector, OwnedVector, Vector};
 use slice::{ImmutableEqVector, ImmutableVector};
+use vec::Vec;
 
 /// Typedef for POSIX file paths.
 /// See `posix::Path` for more info.
@@ -184,7 +184,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
     fn as_vec<'a>(&'a self) -> &'a [u8];
 
     /// Converts the Path into an owned byte vector
-    fn into_vec(self) -> ~[u8];
+    fn into_vec(self) -> Vec<u8>;
 
     /// Returns an object that implements `Show` for printing paths
     ///
@@ -293,7 +293,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
             let extlen = extension.container_as_bytes().len();
             match (name.rposition_elem(&dot), extlen) {
                 (None, 0) | (Some(0), 0) => None,
-                (Some(idx), 0) => Some(name.slice_to(idx).to_owned()),
+                (Some(idx), 0) => Some(Vec::from_slice(name.slice_to(idx))),
                 (idx, extlen) => {
                     let idx = match idx {
                         None | Some(0) => name.len(),
@@ -301,7 +301,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
                     };
 
                     let mut v;
-                    v = slice::with_capacity(idx + extlen + 1);
+                    v = Vec::with_capacity(idx + extlen + 1);
                     v.push_all(name.slice_to(idx));
                     v.push(dot);
                     v.push_all(extension.container_as_bytes());
@@ -441,10 +441,10 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
 pub trait BytesContainer {
     /// Returns a &[u8] representing the receiver
     fn container_as_bytes<'a>(&'a self) -> &'a [u8];
-    /// Consumes the receiver and converts it into ~[u8]
+    /// Consumes the receiver and converts it into Vec<u8>
     #[inline]
-    fn container_into_owned_bytes(self) -> ~[u8] {
-        self.container_as_bytes().to_owned()
+    fn container_into_owned_bytes(self) -> Vec<u8> {
+        Vec::from_slice(self.container_as_bytes())
     }
     /// Returns the receiver interpreted as a utf-8 string, if possible
     #[inline]
@@ -522,10 +522,6 @@ impl BytesContainer for ~str {
         self.as_bytes()
     }
     #[inline]
-    fn container_into_owned_bytes(self) -> ~[u8] {
-        self.into_bytes()
-    }
-    #[inline]
     fn container_as_str<'a>(&'a self) -> Option<&'a str> {
         Some(self.as_slice())
     }
@@ -545,8 +541,15 @@ impl BytesContainer for ~[u8] {
     fn container_as_bytes<'a>(&'a self) -> &'a [u8] {
         self.as_slice()
     }
+}
+
+impl BytesContainer for Vec<u8> {
+    #[inline]
+    fn container_as_bytes<'a>(&'a self) -> &'a [u8] {
+        self.as_slice()
+    }
     #[inline]
-    fn container_into_owned_bytes(self) -> ~[u8] {
+    fn container_into_owned_bytes(self) -> Vec<u8> {
         self
     }
 }
@@ -564,10 +567,6 @@ impl<'a> BytesContainer for str::MaybeOwned<'a> {
         self.as_slice().as_bytes()
     }
     #[inline]
-    fn container_into_owned_bytes(self) -> ~[u8] {
-        self.into_owned().into_bytes()
-    }
-    #[inline]
     fn container_as_str<'b>(&'b self) -> Option<&'b str> {
         Some(self.as_slice())
     }