Module std::finallyDeprecated [-] [+] [src]

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

fn main() { #![feature(unboxed_closures)] use std::finally::Finally; (|| { // ... }).finally(|| { // this code is always run }) }

use std::finally::Finally;

(|| {
    // ...
}).finally(|| {
    // this code is always run
})

Traits

Finally

A trait for executing a destructor unconditionally after a block of code, regardless of whether the blocked fails.

Functions

try_finally

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.