aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/util/io.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/util/io.rs')
-rw-r--r--src/components/util/io.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/components/util/io.rs b/src/components/util/io.rs
index 9fa4dda4a4f..45009723774 100644
--- a/src/components/util/io.rs
+++ b/src/components/util/io.rs
@@ -2,13 +2,19 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-use std::rt::io::{io_error, EndOfFile};
+use std::rt::io::{io_error, IoError};
-/// Ignore the end-of-file condition within a block of code.
-pub fn ignoring_eof<U>(cb: &fn() -> U) -> U {
- io_error::cond.trap(|e|
- match e.kind {
- EndOfFile => (),
- _ => io_error::cond.raise(e)
- }).inside(cb)
+/// Helper for catching an I/O error and wrapping it in a Result object. The
+/// return result will be the last I/O error that happened or the result of the
+/// closure if no error occurred.
+///
+/// FIXME: This is a copy of std::rt::io::result which doesn't exist yet in our
+/// version of Rust. We should switch after the next Rust upgrade.
+pub fn result<T>(cb: &fn() -> T) -> Result<T, IoError> {
+ let mut err = None;
+ let ret = io_error::cond.trap(|e| err = Some(e)).inside(cb);
+ match err {
+ Some(e) => Err(e),
+ None => Ok(ret),
+ }
}