about summary refs log tree commit diff
path: root/src/libstd/rt
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2013-10-05 19:49:32 -0700
committerKevin Ballard <kevin@sb.org>2013-10-15 22:18:30 -0700
commitd6d9b926836b1f1c2b8b3fe4ab35dc63bec7ffcd (patch)
treee197783b86700e71d94c9bc6d0254eb25b16cc0c /src/libstd/rt
parented539e14712539473c3e89604cb69e2307110772 (diff)
downloadrust-d6d9b926836b1f1c2b8b3fe4ab35dc63bec7ffcd.tar.gz
rust-d6d9b926836b1f1c2b8b3fe4ab35dc63bec7ffcd.zip
path2: Adjust the API to remove all the _str mutation methods
Add a new trait BytesContainer that is implemented for both byte vectors
and strings.

Convert Path::from_vec and ::from_str to one function, Path::new().

Remove all the _str-suffixed mutation methods (push, join, with_*,
set_*) and modify the non-suffixed versions to use BytesContainer.
Diffstat (limited to 'src/libstd/rt')
-rw-r--r--src/libstd/rt/io/file.rs28
-rw-r--r--src/libstd/rt/io/support.rs2
-rw-r--r--src/libstd/rt/uv/file.rs12
-rw-r--r--src/libstd/rt/uv/uvio.rs13
4 files changed, 28 insertions, 27 deletions
diff --git a/src/libstd/rt/io/file.rs b/src/libstd/rt/io/file.rs
index 9fbb897c2a7..39c3c5692f8 100644
--- a/src/libstd/rt/io/file.rs
+++ b/src/libstd/rt/io/file.rs
@@ -703,7 +703,7 @@ mod test {
     fn file_test_io_smoke_test() {
         do run_in_mt_newsched_task {
             let message = "it's alright. have a good time";
-            let filename = &Path::from_str("./tmp/file_rt_io_file_test.txt");
+            let filename = &Path::new("./tmp/file_rt_io_file_test.txt");
             {
                 let mut write_stream = open(filename, Create, ReadWrite).unwrap();
                 write_stream.write(message.as_bytes());
@@ -725,7 +725,7 @@ mod test {
     #[test]
     fn file_test_io_invalid_path_opened_without_create_should_raise_condition() {
         do run_in_mt_newsched_task {
-            let filename = &Path::from_str("./tmp/file_that_does_not_exist.txt");
+            let filename = &Path::new("./tmp/file_that_does_not_exist.txt");
             let mut called = false;
             do io_error::cond.trap(|_| {
                 called = true;
@@ -740,7 +740,7 @@ mod test {
     #[test]
     fn file_test_iounlinking_invalid_path_should_raise_condition() {
         do run_in_mt_newsched_task {
-            let filename = &Path::from_str("./tmp/file_another_file_that_does_not_exist.txt");
+            let filename = &Path::new("./tmp/file_another_file_that_does_not_exist.txt");
             let mut called = false;
             do io_error::cond.trap(|_| {
                 called = true;
@@ -757,7 +757,7 @@ mod test {
             use str;
             let message = "ten-four";
             let mut read_mem = [0, .. 8];
-            let filename = &Path::from_str("./tmp/file_rt_io_file_test_positional.txt");
+            let filename = &Path::new("./tmp/file_rt_io_file_test_positional.txt");
             {
                 let mut rw_stream = open(filename, Create, ReadWrite).unwrap();
                 rw_stream.write(message.as_bytes());
@@ -788,7 +788,7 @@ mod test {
             let set_cursor = 4 as u64;
             let mut tell_pos_pre_read;
             let mut tell_pos_post_read;
-            let filename = &Path::from_str("./tmp/file_rt_io_file_test_seeking.txt");
+            let filename = &Path::new("./tmp/file_rt_io_file_test_seeking.txt");
             {
                 let mut rw_stream = open(filename, Create, ReadWrite).unwrap();
                 rw_stream.write(message.as_bytes());
@@ -817,7 +817,7 @@ mod test {
             let final_msg =     "foo-the-bar!!";
             let seek_idx = 3;
             let mut read_mem = [0, .. 13];
-            let filename = &Path::from_str("./tmp/file_rt_io_file_test_seek_and_write.txt");
+            let filename = &Path::new("./tmp/file_rt_io_file_test_seek_and_write.txt");
             {
                 let mut rw_stream = open(filename, Create, ReadWrite).unwrap();
                 rw_stream.write(initial_msg.as_bytes());
@@ -843,7 +843,7 @@ mod test {
             let chunk_two = "asdf";
             let chunk_three = "zxcv";
             let mut read_mem = [0, .. 4];
-            let filename = &Path::from_str("./tmp/file_rt_io_file_test_seek_shakedown.txt");
+            let filename = &Path::new("./tmp/file_rt_io_file_test_seek_shakedown.txt");
             {
                 let mut rw_stream = open(filename, Create, ReadWrite).unwrap();
                 rw_stream.write(initial_msg.as_bytes());
@@ -873,7 +873,7 @@ mod test {
     #[test]
     fn file_test_stat_is_correct_on_is_file() {
         do run_in_mt_newsched_task {
-            let filename = &Path::from_str("./tmp/file_stat_correct_on_is_file.txt");
+            let filename = &Path::new("./tmp/file_stat_correct_on_is_file.txt");
             {
                 let mut fs = open(filename, Create, ReadWrite).unwrap();
                 let msg = "hw";
@@ -891,7 +891,7 @@ mod test {
     #[test]
     fn file_test_stat_is_correct_on_is_dir() {
         do run_in_mt_newsched_task {
-            let filename = &Path::from_str("./tmp/file_stat_correct_on_is_dir");
+            let filename = &Path::new("./tmp/file_stat_correct_on_is_dir");
             mkdir(filename);
             let stat_res = match stat(filename) {
                 Some(s) => s,
@@ -905,7 +905,7 @@ mod test {
     #[test]
     fn file_test_fileinfo_false_when_checking_is_file_on_a_directory() {
         do run_in_mt_newsched_task {
-            let dir = &Path::from_str("./tmp/fileinfo_false_on_dir");
+            let dir = &Path::new("./tmp/fileinfo_false_on_dir");
             mkdir(dir);
             assert!(dir.is_file() == false);
             rmdir(dir);
@@ -915,7 +915,7 @@ mod test {
     #[test]
     fn file_test_fileinfo_check_exists_before_and_after_file_creation() {
         do run_in_mt_newsched_task {
-            let file = &Path::from_str("./tmp/fileinfo_check_exists_b_and_a.txt");
+            let file = &Path::new("./tmp/fileinfo_check_exists_b_and_a.txt");
             {
                 let msg = "foo".as_bytes();
                 let mut w = file.open_writer(Create);
@@ -930,7 +930,7 @@ mod test {
     #[test]
     fn file_test_directoryinfo_check_exists_before_and_after_mkdir() {
         do run_in_mt_newsched_task {
-            let dir = &Path::from_str("./tmp/before_and_after_dir");
+            let dir = &Path::new("./tmp/before_and_after_dir");
             assert!(!dir.exists());
             dir.mkdir();
             assert!(dir.exists());
@@ -944,11 +944,11 @@ mod test {
     fn file_test_directoryinfo_readdir() {
         use str;
         do run_in_mt_newsched_task {
-            let dir = &Path::from_str("./tmp/di_readdir");
+            let dir = &Path::new("./tmp/di_readdir");
             dir.mkdir();
             let prefix = "foo";
             for n in range(0,3) {
-                let f = dir.join_str(format!("{}.txt", n));
+                let f = dir.join(format!("{}.txt", n));
                 let mut w = f.open_writer(Create);
                 let msg_str = (prefix + n.to_str().to_owned()).to_owned();
                 let msg = msg_str.as_bytes();
diff --git a/src/libstd/rt/io/support.rs b/src/libstd/rt/io/support.rs
index a872423c255..31040bc51a1 100644
--- a/src/libstd/rt/io/support.rs
+++ b/src/libstd/rt/io/support.rs
@@ -35,7 +35,7 @@ mod test {
     #[test]
     fn path_like_smoke_test() {
         let expected = if cfg!(unix) { "/home" } else { "C:\\" };
-        let path = Path::from_str(expected);
+        let path = Path::new(expected);
         path.path_as_str(|p| assert!(p == expected));
         path.path_as_str(|p| assert!(p == expected));
     }
diff --git a/src/libstd/rt/uv/file.rs b/src/libstd/rt/uv/file.rs
index 7756448adf8..cb5054626d4 100644
--- a/src/libstd/rt/uv/file.rs
+++ b/src/libstd/rt/uv/file.rs
@@ -391,7 +391,7 @@ mod test {
             let read_mem = vec::from_elem(read_buf_len, 0u8);
             let read_buf = slice_to_uv_buf(read_mem);
             let read_buf_ptr: *Buf = &read_buf;
-            let p = Path::from_str(path_str);
+            let p = Path::new(path_str);
             let open_req = FsRequest::new();
             do open_req.open(&loop_, &p, create_flags as int, mode as int)
             |req, uverr| {
@@ -405,7 +405,7 @@ mod test {
                         assert!(uverr.is_none());
                         let loop_ = req.get_loop();
                         let open_req = FsRequest::new();
-                        do open_req.open(&loop_, &Path::from_str(path_str), read_flags as int,0)
+                        do open_req.open(&loop_, &Path::new(path_str), read_flags as int,0)
                             |req, uverr| {
                             assert!(uverr.is_none());
                             let loop_ = req.get_loop();
@@ -431,7 +431,7 @@ mod test {
                                         assert!(uverr.is_none());
                                         let loop_ = &req.get_loop();
                                         let unlink_req = FsRequest::new();
-                                        do unlink_req.unlink(loop_, &Path::from_str(path_str))
+                                        do unlink_req.unlink(loop_, &Path::new(path_str))
                                         |_,uverr| {
                                             assert!(uverr.is_none());
                                         };
@@ -465,7 +465,7 @@ mod test {
             let write_buf = slice_to_uv_buf(write_val);
             // open/create
             let open_req = FsRequest::new();
-            let result = open_req.open_sync(&loop_, &Path::from_str(path_str),
+            let result = open_req.open_sync(&loop_, &Path::new(path_str),
                                                    create_flags as int, mode as int);
             assert!(result.is_ok());
             let fd = result.unwrap();
@@ -479,7 +479,7 @@ mod test {
             assert!(result.is_ok());
             // re-open
             let open_req = FsRequest::new();
-            let result = open_req.open_sync(&loop_, &Path::from_str(path_str),
+            let result = open_req.open_sync(&loop_, &Path::new(path_str),
                                                    read_flags as int,0);
             assert!(result.is_ok());
             let len = 1028;
@@ -503,7 +503,7 @@ mod test {
                 assert!(result.is_ok());
                 // unlink
                 let unlink_req = FsRequest::new();
-                let result = unlink_req.unlink_sync(&loop_, &Path::from_str(path_str));
+                let result = unlink_req.unlink_sync(&loop_, &Path::new(path_str));
                 assert!(result.is_ok());
             } else { fail2!("nread was 0.. wudn't expectin' that."); }
             loop_.close();
diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs
index a139c4e95ef..d5893d6d014 100644
--- a/src/libstd/rt/uv/uvio.rs
+++ b/src/libstd/rt/uv/uvio.rs
@@ -18,6 +18,7 @@ use ops::Drop;
 use option::*;
 use ptr;
 use str;
+use str::Str;
 use result::*;
 use rt::io::IoError;
 use rt::io::net::ip::{SocketAddr, IpAddr};
@@ -631,7 +632,7 @@ impl IoFactory for UvIoFactory {
                         None => {
                             let stat = req.get_stat();
                             Ok(FileStat {
-                                path: Path::from_str(path_str),
+                                path: Path::new(path_str.as_slice()),
                                 is_file: stat.is_file(),
                                 is_dir: stat.is_dir(),
                                 size: stat.st_size,
@@ -720,8 +721,8 @@ impl IoFactory for UvIoFactory {
                             let rel_paths = req.get_paths();
                             let mut paths = ~[];
                             for r in rel_paths.iter() {
-                                let mut p = Path::from_str(path_str);
-                                p.push_str(*r);
+                                let mut p = Path::new(path_str.as_slice());
+                                p.push(r.as_slice());
                                 paths.push(p);
                             }
                             Ok(paths)
@@ -2179,20 +2180,20 @@ fn file_test_uvio_full_simple_impl() {
         {
             let create_fm = Create;
             let create_fa = ReadWrite;
-            let mut fd = (*io).fs_open(&Path::from_str(path), create_fm, create_fa).unwrap();
+            let mut fd = (*io).fs_open(&Path::new(path), create_fm, create_fa).unwrap();
             let write_buf = write_val.as_bytes();
             fd.write(write_buf);
         }
         {
             let ro_fm = Open;
             let ro_fa = Read;
-            let mut fd = (*io).fs_open(&Path::from_str(path), ro_fm, ro_fa).unwrap();
+            let mut fd = (*io).fs_open(&Path::new(path), ro_fm, ro_fa).unwrap();
             let mut read_vec = [0, .. 1028];
             let nread = fd.read(read_vec).unwrap();
             let read_val = str::from_utf8(read_vec.slice(0, nread as uint));
             assert!(read_val == write_val.to_owned());
         }
-        (*io).fs_unlink(&Path::from_str(path));
+        (*io).fs_unlink(&Path::new(path));
     }
 }