about summary refs log tree commit diff
path: root/src/libcore/finally.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcore/finally.rs')
-rw-r--r--src/libcore/finally.rs102
1 files changed, 49 insertions, 53 deletions
diff --git a/src/libcore/finally.rs b/src/libcore/finally.rs
index 2e358e7a74b..d2b7591b3ef 100644
--- a/src/libcore/finally.rs
+++ b/src/libcore/finally.rs
@@ -8,27 +8,25 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-/*!
-The Finally trait provides a method, `finally` on
-stack closures that emulates Java-style try/finally blocks.
-
-Using the `finally` method is sometimes convenient, but the type rules
-prohibit any shared, mutable state between the "try" case and the
-"finally" case. For advanced cases, the `try_finally` function can
-also be used. See that function for more details.
-
-# Example
-
-```
-use std::finally::Finally;
-
-(|| {
-    // ...
-}).finally(|| {
-    // this code is always run
-})
-```
-*/
+//! The Finally trait provides a method, `finally` on
+//! stack closures that emulates Java-style try/finally blocks.
+//!
+//! Using the `finally` method is sometimes convenient, but the type rules
+//! prohibit any shared, mutable state between the "try" case and the
+//! "finally" case. For advanced cases, the `try_finally` function can
+//! also be used. See that function for more details.
+//!
+//! # Example
+//!
+//! ```
+//! use std::finally::Finally;
+//!
+//! (|| {
+//!     // ...
+//! }).finally(|| {
+//!     // this code is always run
+//! })
+//! ```
 
 #![experimental]
 
@@ -58,38 +56,36 @@ impl<T> Finally<T> for fn() -> T {
     }
 }
 
-/**
- * The most general form of the `finally` functions. The function
- * `try_fn` will be invoked first; whether or not it panics, the
- * function `finally_fn` will be invoked next. The two parameters
- * `mutate` and `drop` are used to thread state through the two
- * closures. `mutate` is used for any shared, mutable state that both
- * closures require access to; `drop` is used for any state that the
- * `try_fn` requires ownership of.
- *
- * **WARNING:** While shared, mutable state between the try and finally
- * function is often necessary, one must be very careful; the `try`
- * function could have panicked at any point, so the values of the shared
- * state may be inconsistent.
- *
- * # Example
- *
- * ```
- * use std::finally::try_finally;
- *
- * struct State<'a> { buffer: &'a mut [u8], len: uint }
- * # let mut buf = [];
- * let mut state = State { buffer: &mut buf, len: 0 };
- * try_finally(
- *     &mut state, (),
- *     |state, ()| {
- *         // use state.buffer, state.len
- *     },
- *     |state| {
- *         // use state.buffer, state.len to cleanup
- *     })
- * ```
- */
+/// The most general form of the `finally` functions. The function
+/// `try_fn` will be invoked first; whether or not it panics, the
+/// function `finally_fn` will be invoked next. The two parameters
+/// `mutate` and `drop` are used to thread state through the two
+/// closures. `mutate` is used for any shared, mutable state that both
+/// closures require access to; `drop` is used for any state that the
+/// `try_fn` requires ownership of.
+///
+/// **WARNING:** While shared, mutable state between the try and finally
+/// function is often necessary, one must be very careful; the `try`
+/// function could have panicked at any point, so the values of the shared
+/// state may be inconsistent.
+///
+/// # Example
+///
+/// ```
+/// use std::finally::try_finally;
+///
+/// struct State<'a> { buffer: &'a mut [u8], len: uint }
+/// # let mut buf = [];
+/// let mut state = State { buffer: &mut buf, len: 0 };
+/// try_finally(
+///     &mut state, (),
+///     |state, ()| {
+///         // use state.buffer, state.len
+///     },
+///     |state| {
+///         // use state.buffer, state.len to cleanup
+///     })
+/// ```
 pub fn try_finally<T,U,R>(mutate: &mut T,
                           drop: U,
                           try_fn: |&mut T, U| -> R,