Skip to content

Commit 3015949

Browse files
huonwalexcrichton
authored andcommitted
std,native,green,rustuv: make readdir return Vec.
Replacing `~[]`. This also makes the `walk_dir` iterator use a `Vec` internally.
1 parent a65411e commit 3015949

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

src/libnative/io/file_unix.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,11 @@ pub fn mkdir(p: &CString, mode: io::FilePermission) -> IoResult<()> {
340340
}))
341341
}
342342

343-
pub fn readdir(p: &CString) -> IoResult<~[Path]> {
343+
pub fn readdir(p: &CString) -> IoResult<Vec<Path>> {
344344
use libc::{dirent_t};
345345
use libc::{opendir, readdir_r, closedir};
346346

347-
fn prune(root: &CString, dirs: ~[Path]) -> ~[Path] {
347+
fn prune(root: &CString, dirs: Vec<Path>) -> Vec<Path> {
348348
let root = unsafe { CString::new(root.with_ref(|p| p), false) };
349349
let root = Path::new(root);
350350

@@ -365,7 +365,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
365365
let dir_ptr = p.with_ref(|buf| unsafe { opendir(buf) });
366366

367367
if dir_ptr as uint != 0 {
368-
let mut paths = ~[];
368+
let mut paths = vec!();
369369
let mut entry_ptr = 0 as *mut dirent_t;
370370
while unsafe { readdir_r(dir_ptr, ptr, &mut entry_ptr) == 0 } {
371371
if entry_ptr.is_null() { break }
@@ -571,4 +571,3 @@ mod tests {
571571
}
572572
}
573573
}
574-

src/libnative/io/file_win32.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ pub fn mkdir(p: &CString, _mode: io::FilePermission) -> IoResult<()> {
323323
})
324324
}
325325

326-
pub fn readdir(p: &CString) -> IoResult<~[Path]> {
326+
pub fn readdir(p: &CString) -> IoResult<Vec<Path>> {
327327
use rt::global_heap::malloc_raw;
328328

329-
fn prune(root: &CString, dirs: ~[Path]) -> ~[Path] {
329+
fn prune(root: &CString, dirs: Vec<Path>) -> Vec<Path> {
330330
let root = unsafe { CString::new(root.with_ref(|p| p), false) };
331331
let root = Path::new(root);
332332

@@ -346,7 +346,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
346346
let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint);
347347
let find_handle = libc::FindFirstFileW(path_ptr, wfd_ptr as libc::HANDLE);
348348
if find_handle as libc::c_int != libc::INVALID_HANDLE_VALUE {
349-
let mut paths = ~[];
349+
let mut paths = vec!();
350350
let mut more_files = 1 as libc::c_int;
351351
while more_files != 0 {
352352
let fp_buf = rust_list_dir_wfd_fp_buf(wfd_ptr as *c_void);

src/libnative/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl rtio::IoFactory for IoFactory {
217217
fn fs_rename(&mut self, path: &CString, to: &CString) -> IoResult<()> {
218218
file::rename(path, to)
219219
}
220-
fn fs_readdir(&mut self, path: &CString, _flags: c_int) -> IoResult<~[Path]> {
220+
fn fs_readdir(&mut self, path: &CString, _flags: c_int) -> IoResult<Vec<Path>> {
221221
file::readdir(path)
222222
}
223223
fn fs_lstat(&mut self, path: &CString) -> IoResult<io::FileStat> {

src/librustuv/file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ impl FsRequest {
152152
}
153153

154154
pub fn readdir(loop_: &Loop, path: &CString, flags: c_int)
155-
-> Result<~[Path], UvError>
155+
-> Result<Vec<Path>, UvError>
156156
{
157157
execute(|req, cb| unsafe {
158158
uvll::uv_fs_readdir(loop_.handle,
159159
req, path.with_ref(|p| p), flags, cb)
160160
}).map(|req| unsafe {
161-
let mut paths = ~[];
161+
let mut paths = vec!();
162162
let path = CString::new(path.with_ref(|p| p), false);
163163
let parent = Path::new(path);
164164
let _ = c_str::from_c_multistring(req.get_ptr() as *libc::c_char,

src/librustuv/uvio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl IoFactory for UvIoFactory {
234234
r.map_err(uv_error_to_io_error)
235235
}
236236
fn fs_readdir(&mut self, path: &CString, flags: c_int)
237-
-> Result<~[Path], IoError>
237+
-> Result<Vec<Path>, IoError>
238238
{
239239
let r = FsRequest::readdir(&self.loop_, path, flags);
240240
r.map_err(uv_error_to_io_error)

src/libstd/io/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ pub fn rmdir(path: &Path) -> IoResult<()> {
483483
/// Will return an error if the provided `from` doesn't exist, the process lacks
484484
/// permissions to view the contents or if the `path` points at a non-directory
485485
/// file
486-
pub fn readdir(path: &Path) -> IoResult<~[Path]> {
486+
pub fn readdir(path: &Path) -> IoResult<Vec<Path>> {
487487
LocalIo::maybe_raise(|io| {
488488
io.fs_readdir(&path.to_c_str(), 0)
489489
})
@@ -498,7 +498,7 @@ pub fn walk_dir(path: &Path) -> IoResult<Directories> {
498498

499499
/// An iterator which walks over a directory
500500
pub struct Directories {
501-
stack: ~[Path],
501+
stack: Vec<Path>,
502502
}
503503

504504
impl Iterator<Path> for Directories {

src/libstd/rt/rtio.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use path::Path;
2020
use result::Err;
2121
use rt::local::Local;
2222
use rt::task::Task;
23+
use vec::Vec;
2324

2425
use ai = io::net::addrinfo;
2526
use io;
@@ -168,7 +169,7 @@ pub trait IoFactory {
168169
fn fs_rmdir(&mut self, path: &CString) -> IoResult<()>;
169170
fn fs_rename(&mut self, path: &CString, to: &CString) -> IoResult<()>;
170171
fn fs_readdir(&mut self, path: &CString, flags: c_int) ->
171-
IoResult<~[Path]>;
172+
IoResult<Vec<Path>>;
172173
fn fs_lstat(&mut self, path: &CString) -> IoResult<FileStat>;
173174
fn fs_chown(&mut self, path: &CString, uid: int, gid: int) ->
174175
IoResult<()>;

0 commit comments

Comments
 (0)