about summary refs log tree commit diff
path: root/src/libstd/condition.rs
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-12-04 15:20:26 -0800
committerPatrick Walton <pcwalton@mimiga.net>2013-12-10 15:13:12 -0800
commitec5603bf13ccb95c311fe5ca193a32efe07147a2 (patch)
tree6cf2f33e901d673ba63fa781ddb5167beaae42f8 /src/libstd/condition.rs
parentab3bec91d77150e434ac1480fbb3935213e33dca (diff)
downloadrust-ec5603bf13ccb95c311fe5ca193a32efe07147a2.tar.gz
rust-ec5603bf13ccb95c311fe5ca193a32efe07147a2.zip
librustpkg: Make `io::ignore_io_error()` use RAII; remove a few more
cells.
Diffstat (limited to 'src/libstd/condition.rs')
-rw-r--r--src/libstd/condition.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/libstd/condition.rs b/src/libstd/condition.rs
index e34e94ac10c..c5d6ce2f3df 100644
--- a/src/libstd/condition.rs
+++ b/src/libstd/condition.rs
@@ -162,7 +162,7 @@ impl<T, U> Condition<T, U> {
 ///
 /// Normally this object is not dealt with directly, but rather it's directly
 /// used after being returned from `trap`
-struct Trap<'self, T, U> {
+pub struct Trap<'self, T, U> {
     priv cond: &'self Condition<T, U>,
     priv handler: @Handler<T, U>
 }
@@ -187,10 +187,24 @@ impl<'self, T, U> Trap<'self, T, U> {
         local_data::set(self.cond.key, self.handler);
         inner()
     }
+
+    /// Returns a guard that will automatically reset the condition upon
+    /// exit of the scope. This is useful if you want to use conditions with
+    /// an RAII pattern.
+    pub fn guard(&self) -> Guard<'self,T,U> {
+        let guard = Guard {
+            cond: self.cond
+        };
+        debug!("Guard: pushing handler to TLS");
+        local_data::set(self.cond.key, self.handler);
+        guard
+    }
 }
 
-#[doc(hidden)]
-struct Guard<'self, T, U> {
+/// A guard that will automatically reset the condition handler upon exit of
+/// the scope. This is useful if you want to use conditions with an RAII
+/// pattern.
+pub struct Guard<'self, T, U> {
     priv cond: &'self Condition<T, U>
 }