]> git.lizzy.rs Git - rust.git/commitdiff
std,native,green,rustuv: make readdir return `Vec`.
authorHuon Wilson <dbau.pp+github@gmail.com>
Wed, 9 Apr 2014 01:45:20 +0000 (11:45 +1000)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 10 Apr 2014 22:21:58 +0000 (15:21 -0700)
Replacing `~[]`. This also makes the `walk_dir` iterator use a `Vec`
internally.

src/libnative/io/file_unix.rs
src/libnative/io/file_win32.rs
src/libnative/io/mod.rs
src/librustuv/file.rs
src/librustuv/uvio.rs
src/libstd/io/fs.rs
src/libstd/rt/rtio.rs

index 56460166b48a4c7b3cdfbb23f5ec7fb18bccea1a..5446ab2950e44bb136787d31f9c3a7886b7eb92a 100644 (file)
@@ -340,11 +340,11 @@ pub fn mkdir(p: &CString, mode: io::FilePermission) -> IoResult<()> {
     }))
 }
 
-pub fn readdir(p: &CString) -> IoResult<~[Path]> {
+pub fn readdir(p: &CString) -> IoResult<Vec<Path>> {
     use libc::{dirent_t};
     use libc::{opendir, readdir_r, closedir};
 
-    fn prune(root: &CString, dirs: ~[Path]) -> ~[Path] {
+    fn prune(root: &CString, dirs: Vec<Path>) -> Vec<Path> {
         let root = unsafe { CString::new(root.with_ref(|p| p), false) };
         let root = Path::new(root);
 
@@ -365,7 +365,7 @@ fn prune(root: &CString, dirs: ~[Path]) -> ~[Path] {
     let dir_ptr = p.with_ref(|buf| unsafe { opendir(buf) });
 
     if dir_ptr as uint != 0 {
-        let mut paths = ~[];
+        let mut paths = vec!();
         let mut entry_ptr = 0 as *mut dirent_t;
         while unsafe { readdir_r(dir_ptr, ptr, &mut entry_ptr) == 0 } {
             if entry_ptr.is_null() { break }
@@ -571,4 +571,3 @@ fn test_cfile() {
         }
     }
 }
-
index 3e8ee55df94fc934350364a38b1fff61752e33ac..8090042f090c9aa7e53f616660bc68a8c65917b0 100644 (file)
@@ -323,10 +323,10 @@ pub fn mkdir(p: &CString, _mode: io::FilePermission) -> IoResult<()> {
     })
 }
 
-pub fn readdir(p: &CString) -> IoResult<~[Path]> {
+pub fn readdir(p: &CString) -> IoResult<Vec<Path>> {
     use rt::global_heap::malloc_raw;
 
-    fn prune(root: &CString, dirs: ~[Path]) -> ~[Path] {
+    fn prune(root: &CString, dirs: Vec<Path>) -> Vec<Path> {
         let root = unsafe { CString::new(root.with_ref(|p| p), false) };
         let root = Path::new(root);
 
@@ -346,7 +346,7 @@ fn prune(root: &CString, dirs: ~[Path]) -> ~[Path] {
         let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint);
         let find_handle = libc::FindFirstFileW(path_ptr, wfd_ptr as libc::HANDLE);
         if find_handle as libc::c_int != libc::INVALID_HANDLE_VALUE {
-            let mut paths = ~[];
+            let mut paths = vec!();
             let mut more_files = 1 as libc::c_int;
             while more_files != 0 {
                 let fp_buf = rust_list_dir_wfd_fp_buf(wfd_ptr as *c_void);
index ffca0dbe3dc6056890cd6a7eef296882652c5c56..cc432555abb92923213bcb4e6510e6b33d8a1505 100644 (file)
@@ -217,7 +217,7 @@ fn fs_rmdir(&mut self, path: &CString) -> IoResult<()> {
     fn fs_rename(&mut self, path: &CString, to: &CString) -> IoResult<()> {
         file::rename(path, to)
     }
-    fn fs_readdir(&mut self, path: &CString, _flags: c_int) -> IoResult<~[Path]> {
+    fn fs_readdir(&mut self, path: &CString, _flags: c_int) -> IoResult<Vec<Path>> {
         file::readdir(path)
     }
     fn fs_lstat(&mut self, path: &CString) -> IoResult<io::FileStat> {
index acb7a8184dd0782da034d1281735a33d1c9a72ec..69be32a60211d5812e7a6ae13aad756a407922fb 100644 (file)
@@ -152,13 +152,13 @@ pub fn chmod(loop_: &Loop, path: &CString, mode: c_int)
     }
 
     pub fn readdir(loop_: &Loop, path: &CString, flags: c_int)
-        -> Result<~[Path], UvError>
+        -> Result<Vec<Path>, UvError>
     {
         execute(|req, cb| unsafe {
             uvll::uv_fs_readdir(loop_.handle,
                                 req, path.with_ref(|p| p), flags, cb)
         }).map(|req| unsafe {
-            let mut paths = ~[];
+            let mut paths = vec!();
             let path = CString::new(path.with_ref(|p| p), false);
             let parent = Path::new(path);
             let _ = c_str::from_c_multistring(req.get_ptr() as *libc::c_char,
index 424849bbf0eab83d37da97c044628fabaff79a34..55456bb548e91ec480d1814cfce5c75f0bf8dc06 100644 (file)
@@ -234,7 +234,7 @@ fn fs_chmod(&mut self, path: &CString,
         r.map_err(uv_error_to_io_error)
     }
     fn fs_readdir(&mut self, path: &CString, flags: c_int)
-        -> Result<~[Path], IoError>
+        -> Result<Vec<Path>, IoError>
     {
         let r = FsRequest::readdir(&self.loop_, path, flags);
         r.map_err(uv_error_to_io_error)
index 2fea002d4197f85a59fc4617b65331b389dea61b..b8a58c5cf1040e99e9e4cef99292d1963a405279 100644 (file)
@@ -483,7 +483,7 @@ pub fn rmdir(path: &Path) -> IoResult<()> {
 /// Will return an error if the provided `from` doesn't exist, the process lacks
 /// permissions to view the contents or if the `path` points at a non-directory
 /// file
-pub fn readdir(path: &Path) -> IoResult<~[Path]> {
+pub fn readdir(path: &Path) -> IoResult<Vec<Path>> {
     LocalIo::maybe_raise(|io| {
         io.fs_readdir(&path.to_c_str(), 0)
     })
@@ -498,7 +498,7 @@ pub fn walk_dir(path: &Path) -> IoResult<Directories> {
 
 /// An iterator which walks over a directory
 pub struct Directories {
-    stack: ~[Path],
+    stack: Vec<Path>,
 }
 
 impl Iterator<Path> for Directories {
index 1750e685627d8a1deebb093d23bc1d6a4187ad51..cc8356d2b9a04bcaefe5335cf3983dfd23b63945 100644 (file)
@@ -20,6 +20,7 @@
 use result::Err;
 use rt::local::Local;
 use rt::task::Task;
+use vec::Vec;
 
 use ai = io::net::addrinfo;
 use io;
@@ -168,7 +169,7 @@ fn fs_chmod(&mut self, path: &CString,
     fn fs_rmdir(&mut self, path: &CString) -> IoResult<()>;
     fn fs_rename(&mut self, path: &CString, to: &CString) -> IoResult<()>;
     fn fs_readdir(&mut self, path: &CString, flags: c_int) ->
-        IoResult<~[Path]>;
+        IoResult<Vec<Path>>;
     fn fs_lstat(&mut self, path: &CString) -> IoResult<FileStat>;
     fn fs_chown(&mut self, path: &CString, uid: int, gid: int) ->
         IoResult<()>;