about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-11-04 12:21:11 -0800
committerbors <bors@rust-lang.org>2013-11-04 12:21:11 -0800
commit658637baf45b41e4cff049440bc07f267d810218 (patch)
tree019eee1761d43461ef06f1e5307b57b0b8b47019 /src/libsyntax/ext
parent70e9b5ab3912da84a32557bc1a34db5fb2178927 (diff)
parent3c3ed1499a9b9e23d4a2d2243a7b0b1c9015f34b (diff)
downloadrust-658637baf45b41e4cff049440bc07f267d810218.tar.gz
rust-658637baf45b41e4cff049440bc07f267d810218.zip
auto merge of #10179 : alexcrichton/rust/rt-improvements, r=cmr
This fleshes out the io::file module a fair bit more, adding all of the functionality that I can think of that we would want. Some questions about the representation which I'm curious about:

* I modified `FileStat` to be a little less platform-agnostic, but it's still fairly platform-specific. I don't want to hide information that we have, but I don't want to depend on this information being available. One possible route is to have an `extra` field which has all this os-dependent stuff which is clearly documented as it should be avoided.

* Does it make sense for directory functions to be top-level functions instead of static methods? It seems silly to import `std::rt::io::file` and `std::rt::io::File` at the top of files that need to deal with directories and files.
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/source_util.rs26
1 files changed, 8 insertions, 18 deletions
diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs
index fda6f782af4..75b5ab81f9b 100644
--- a/src/libsyntax/ext/source_util.rs
+++ b/src/libsyntax/ext/source_util.rs
@@ -20,8 +20,7 @@ use parse::token::{get_ident_interner};
 use print::pprust;
 
 use std::rt::io;
-use std::rt::io::Reader;
-use std::rt::io::file::FileInfo;
+use std::rt::io::File;
 use std::str;
 
 // These macros all relate to the file system; they either return
@@ -92,17 +91,13 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
     -> base::MacResult {
     let file = get_single_str_from_tts(cx, sp, tts, "include_str!");
     let file = res_rel_file(cx, sp, &Path::new(file));
-    let mut error = None;
-    let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside {
-        file.open_reader(io::Open).read_to_end()
-    };
-    match error {
-        Some(e) => {
+    let bytes = match io::result(|| File::open(&file).read_to_end()) {
+        Err(e) => {
             cx.span_fatal(sp, format!("couldn't read {}: {}",
                                       file.display(), e.desc));
         }
-        None => {}
-    }
+        Ok(bytes) => bytes,
+    };
     match str::from_utf8_owned_opt(bytes) {
         Some(s) => base::MRExpr(cx.expr_str(sp, s.to_managed())),
         None => {
@@ -118,17 +113,12 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
 
     let file = get_single_str_from_tts(cx, sp, tts, "include_bin!");
     let file = res_rel_file(cx, sp, &Path::new(file));
-
-    let mut error = None;
-    let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside {
-        file.open_reader(io::Open).read_to_end()
-    };
-    match error {
-        Some(e) => {
+    match io::result(|| File::open(&file).read_to_end()) {
+        Err(e) => {
             cx.span_fatal(sp, format!("couldn't read {}: {}",
                                       file.display(), e.desc));
         }
-        None => {
+        Ok(bytes) => {
             let bytes = at_vec::to_managed_move(bytes);
             base::MRExpr(cx.expr_lit(sp, ast::lit_binary(bytes)))
         }