aboutsummaryrefslogtreecommitdiffstats
path: root/src/guard.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-04-03 02:45:53 -0500
committerJesse Luehrs <doy@tozt.net>2013-04-03 02:46:18 -0500
commit0465ddb62b7708819a668aced5ade29cde6a8be0 (patch)
tree86ef870df906b279ed9e4c63ee5a7ee1b41b3bd7 /src/guard.rs
parent3e95a135f67b52589957c14595ad3837c7f2f1e5 (diff)
downloadrust-term-0465ddb62b7708819a668aced5ade29cde6a8be0.tar.gz
rust-term-0465ddb62b7708819a668aced5ade29cde6a8be0.zip
split this out into a separate module too
Diffstat (limited to 'src/guard.rs')
-rw-r--r--src/guard.rs14
1 files changed, 14 insertions, 0 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)();
+ }
+}