diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-12-04 15:20:26 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-12-10 15:13:12 -0800 |
| commit | ec5603bf13ccb95c311fe5ca193a32efe07147a2 (patch) | |
| tree | 6cf2f33e901d673ba63fa781ddb5167beaae42f8 /src/libstd/condition.rs | |
| parent | ab3bec91d77150e434ac1480fbb3935213e33dca (diff) | |
| download | rust-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.rs | 20 |
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> } |
