diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-08-26 16:54:31 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-08-27 14:37:04 -0700 |
| commit | 0c6e470a257fc546555aa10ededded4a77460a71 (patch) | |
| tree | fb54281612401dba521efedab7626474c80195a9 /src/libcore/io.rs | |
| parent | 3a1582012eafb8b672e15b12b5424e72ea6096af (diff) | |
Convert core::result to camel case
Diffstat (limited to 'src/libcore/io.rs')
| -rw-r--r-- | src/libcore/io.rs | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 71d8129b035..dd98e471d7d 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -4,7 +4,7 @@ Module: io Basic input/output */ -import result::result; +import result::Result; import dvec::{DVec, dvec}; import libc::{c_int, c_long, c_uint, c_void, size_t, ssize_t}; @@ -264,16 +264,16 @@ fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader { fn stdin() -> Reader { rustrt::rust_get_stdin() as Reader } -fn file_reader(path: &Path) -> result<Reader, ~str> { +fn file_reader(path: &Path) -> Result<Reader, ~str> { let f = os::as_c_charp(path.to_str(), |pathbuf| { os::as_c_charp("r", |modebuf| libc::fopen(pathbuf, modebuf) ) }); - return if f as uint == 0u { result::err(~"error opening " + return if f as uint == 0u { result::Err(~"error opening " + path.to_str()) } else { - result::ok(FILE_reader(f, true)) + result::Ok(FILE_reader(f, true)) } } @@ -421,7 +421,7 @@ fn fd_writer(fd: fd_t, cleanup: bool) -> Writer { fn mk_file_writer(path: &Path, flags: ~[FileFlag]) - -> result<Writer, ~str> { + -> Result<Writer, ~str> { #[cfg(windows)] fn wb() -> c_int { (O_WRONLY | O_BINARY) as c_int } @@ -443,10 +443,10 @@ fn mk_file_writer(path: &Path, flags: ~[FileFlag]) (S_IRUSR | S_IWUSR) as c_int) }; if fd < (0 as c_int) { - result::err(fmt!("error opening %s: %s", path.to_str(), + result::Err(fmt!("error opening %s: %s", path.to_str(), os::last_os_error())) } else { - result::ok(fd_writer(fd, true)) + result::Ok(fd_writer(fd, true)) } } @@ -623,21 +623,21 @@ impl<T: Writer> T : WriterUtil { fn write_u8(n: u8) { self.write(&[n]) } } -fn file_writer(path: &Path, flags: ~[FileFlag]) -> result<Writer, ~str> { - result::chain(mk_file_writer(path, flags), |w| result::ok(w)) +fn file_writer(path: &Path, flags: ~[FileFlag]) -> Result<Writer, ~str> { + result::chain(mk_file_writer(path, flags), |w| result::Ok(w)) } // FIXME: fileflags // #2004 -fn buffered_file_writer(path: &Path) -> result<Writer, ~str> { +fn buffered_file_writer(path: &Path) -> Result<Writer, ~str> { let f = do os::as_c_charp(path.to_str()) |pathbuf| { do os::as_c_charp("w") |modebuf| { libc::fopen(pathbuf, modebuf) } }; - return if f as uint == 0u { result::err(~"error opening " + return if f as uint == 0u { result::Err(~"error opening " + path.to_str()) } - else { result::ok(FILE_writer(f, true)) } + else { result::Ok(FILE_writer(f, true)) } } // FIXME (#2004) it would be great if this could be a const @@ -719,21 +719,21 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) -> return bpos as uint; } -fn read_whole_file_str(file: &Path) -> result<~str, ~str> { +fn read_whole_file_str(file: &Path) -> Result<~str, ~str> { result::chain(read_whole_file(file), |bytes| { if str::is_utf8(bytes) { - result::ok(str::from_bytes(bytes)) + result::Ok(str::from_bytes(bytes)) } else { - result::err(file.to_str() + ~" is not UTF-8") + result::Err(file.to_str() + ~" is not UTF-8") } }) } // FIXME (#2004): implement this in a low-level way. Going through the // abstractions is pointless. -fn read_whole_file(file: &Path) -> result<~[u8], ~str> { +fn read_whole_file(file: &Path) -> Result<~[u8], ~str> { result::chain(file_reader(file), |rdr| { - result::ok(rdr.read_whole_stream()) + result::Ok(rdr.read_whole_stream()) }) } @@ -892,30 +892,30 @@ mod tests { #[test] fn file_reader_not_exist() { match io::file_reader(&Path("not a file")) { - result::err(e) => { + result::Err(e) => { assert e == ~"error opening not a file"; } - result::ok(_) => fail + result::Ok(_) => fail } } #[test] fn file_writer_bad_name() { match io::file_writer(&Path("?/?"), ~[]) { - result::err(e) => { + result::Err(e) => { assert str::starts_with(e, "error opening"); } - result::ok(_) => fail + result::Ok(_) => fail } } #[test] fn buffered_file_writer_bad_name() { match io::buffered_file_writer(&Path("?/?")) { - result::err(e) => { + result::Err(e) => { assert str::starts_with(e, "error opening"); } - result::ok(_) => fail + result::Ok(_) => fail } } |
