diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/guard.rs | 14 | ||||
-rw-r--r-- | src/ios.rs | 2 | ||||
-rw-r--r-- | src/term.rs | 1 | ||||
-rw-r--r-- | src/util.rs | 15 |
4 files changed, 16 insertions, 16 deletions
diff --git a/src/guard.rs b/src/guard.rs new file mode 100644 index 0000000..75a28aa --- /dev/null +++ b/src/guard.rs @@ -0,0 +1,14 @@ +pub fn guard<T> (finally: ~fn (), body: &fn () -> T) -> T { + let _guard = Guard { finally: finally }; + body() +} + +struct Guard { + priv finally: ~fn (), +} + +impl Drop for Guard { + fn finalize (&self) { + (self.finally)(); + } +} @@ -1,5 +1,5 @@ use core::libc::{c_int,c_void}; -use util::guard; +use guard::guard; pub fn cooked () -> int { unsafe { c::cooked() as int } diff --git a/src/term.rs b/src/term.rs index e876dfa..3f9690e 100644 --- a/src/term.rs +++ b/src/term.rs @@ -12,3 +12,4 @@ pub mod info; pub mod ios; mod trie; mod util; +mod guard; diff --git a/src/util.rs b/src/util.rs index 1a4e1c3..2b3580e 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,20 +1,5 @@ use core::libc::{c_int,c_uint}; -pub fn guard<T> (finally: ~fn (), body: &fn () -> T) -> T { - let _guard = Guard { finally: finally }; - body() -} - -struct Guard { - priv finally: ~fn (), -} - -impl Drop for Guard { - fn finalize (&self) { - (self.finally)(); - } -} - // XXX huge hack until there's a better built-in way to do this pub fn timed_read (timeout: int) -> Option<char> { let first = unsafe { io_helper::timed_read(timeout as c_int) }; |