Skip to content

Commit 3478589

Browse files
committed
std and rustc: cleanup uses of result methods
1 parent ea106f7 commit 3478589

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

src/libstd/io.rs

+25-27
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,26 @@ implement `Reader` and `Writer`, where appropriate.
4646

4747
#[allow(missing_doc)];
4848

49-
use result::Result;
50-
49+
use cast;
5150
use clone::Clone;
5251
use container::Container;
5352
use int;
54-
use libc;
55-
use libc::{c_int, c_long, c_void, size_t, ssize_t};
53+
use iterator::IteratorUtil;
5654
use libc::consts::os::posix88::*;
55+
use libc::{c_int, c_long, c_void, size_t, ssize_t};
56+
use libc;
5757
use num;
58+
use ops::Drop;
5859
use os;
59-
use cast;
6060
use path::Path;
61-
use ops::Drop;
62-
use iterator::IteratorUtil;
6361
use ptr;
64-
use result;
65-
use str;
62+
use result::{Result, Ok, Err};
6663
use str::{StrSlice, OwnedStr};
64+
use str;
6765
use to_str::ToStr;
6866
use uint;
69-
use vec;
7067
use vec::{MutableVector, ImmutableVector, OwnedVector, OwnedCopyableVector, CopyableVector};
68+
use vec;
7169

7270
#[allow(non_camel_case_types)] // not sure what to do about this
7371
pub type fd_t = c_int;
@@ -1038,9 +1036,9 @@ pub fn file_reader(path: &Path) -> Result<@Reader, ~str> {
10381036
};
10391037
10401038
if f as uint == 0u {
1041-
result::Err(~"error opening " + path.to_str())
1039+
Err(~"error opening " + path.to_str())
10421040
} else {
1043-
result::Ok(FILE_reader(f, true))
1041+
Ok(FILE_reader(f, true))
10441042
}
10451043
}
10461044
@@ -1287,10 +1285,9 @@ pub fn mk_file_writer(path: &Path, flags: &[FileFlag])
12871285
}
12881286
};
12891287
if fd < (0 as c_int) {
1290-
result::Err(fmt!("error opening %s: %s", path.to_str(),
1291-
os::last_os_error()))
1288+
Err(fmt!("error opening %s: %s", path.to_str(), os::last_os_error()))
12921289
} else {
1293-
result::Ok(fd_writer(fd, true))
1290+
Ok(fd_writer(fd, true))
12941291
}
12951292
}
12961293

@@ -1559,7 +1556,7 @@ impl<T:Writer> WriterUtil for T {
15591556
}
15601557

15611558
pub fn file_writer(path: &Path, flags: &[FileFlag]) -> Result<@Writer, ~str> {
1562-
mk_file_writer(path, flags).chain(|w| result::Ok(w))
1559+
mk_file_writer(path, flags).chain(|w| Ok(w))
15631560
}
15641561

15651562

@@ -1572,9 +1569,9 @@ pub fn buffered_file_writer(path: &Path) -> Result<@Writer, ~str> {
15721569
}
15731570
};
15741571
return if f as uint == 0u {
1575-
result::Err(~"error opening " + path.to_str())
1572+
Err(~"error opening " + path.to_str())
15761573
} else {
1577-
result::Ok(FILE_writer(f, true))
1574+
Ok(FILE_writer(f, true))
15781575
}
15791576
}
15801577
}
@@ -1728,9 +1725,9 @@ pub fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) ->
17281725
pub fn read_whole_file_str(file: &Path) -> Result<~str, ~str> {
17291726
do read_whole_file(file).chain |bytes| {
17301727
if str::is_utf8(bytes) {
1731-
result::Ok(str::from_bytes(bytes))
1728+
Ok(str::from_bytes(bytes))
17321729
} else {
1733-
result::Err(file.to_str() + " is not UTF-8")
1730+
Err(file.to_str() + " is not UTF-8")
17341731
}
17351732
}
17361733
}
@@ -1739,7 +1736,7 @@ pub fn read_whole_file_str(file: &Path) -> Result<~str, ~str> {
17391736
// abstractions is pointless.
17401737
pub fn read_whole_file(file: &Path) -> Result<~[u8], ~str> {
17411738
do file_reader(file).chain |rdr| {
1742-
result::Ok(rdr.read_whole_stream())
1739+
Ok(rdr.read_whole_stream())
17431740
}
17441741
}
17451742

@@ -1839,6 +1836,7 @@ mod tests {
18391836
use io::{BytesWriter, SeekCur, SeekEnd, SeekSet};
18401837
use io;
18411838
use path::Path;
1839+
use result::{Ok, Err};
18421840
use result;
18431841
use u64;
18441842
use vec;
@@ -1939,10 +1937,10 @@ mod tests {
19391937
#[test]
19401938
fn file_reader_not_exist() {
19411939
match io::file_reader(&Path("not a file")) {
1942-
result::Err(e) => {
1940+
Err(e) => {
19431941
assert_eq!(e, ~"error opening not a file");
19441942
}
1945-
result::Ok(_) => fail!()
1943+
Ok(_) => fail!()
19461944
}
19471945
}
19481946
@@ -1980,20 +1978,20 @@ mod tests {
19801978
#[test]
19811979
fn file_writer_bad_name() {
19821980
match io::file_writer(&Path("?/?"), []) {
1983-
result::Err(e) => {
1981+
Err(e) => {
19841982
assert!(e.starts_with("error opening"));
19851983
}
1986-
result::Ok(_) => fail!()
1984+
Ok(_) => fail!()
19871985
}
19881986
}
19891987
19901988
#[test]
19911989
fn buffered_file_writer_bad_name() {
19921990
match io::buffered_file_writer(&Path("?/?")) {
1993-
result::Err(e) => {
1991+
Err(e) => {
19941992
assert!(e.starts_with("error opening"));
19951993
}
1996-
result::Ok(_) => fail!()
1994+
Ok(_) => fail!()
19971995
}
19981996
}
19991997

0 commit comments

Comments
 (0)