Skip to content

Commit

Permalink
std: Change Finally to take &mut self
Browse files Browse the repository at this point in the history
As with the previous commits, the Finally trait is primarily implemented for
closures, so the trait was modified from `&self` to `&mut self`. This will
require that any closure variable invoked with `finally` to be stored in a
mutable slot.

[breaking-change]
  • Loading branch information
alexcrichton committed Apr 23, 2014
1 parent 2b2d1e1 commit b4ecbe9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/libstd/rt/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Task {
/// This function is *not* meant to be abused as a "try/catch" block. This
/// is meant to be used at the absolute boundaries of a task's lifetime, and
/// only for that purpose.
pub fn run(~self, f: ||) -> ~Task {
pub fn run(~self, mut f: ||) -> ~Task {
// Need to put ourselves into TLS, but also need access to the unwinder.
// Unsafely get a handle to the task so we can continue to use it after
// putting it in tls (so we can invoke the unwinder).
Expand Down
10 changes: 5 additions & 5 deletions src/libstd/unstable/finally.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ use ops::Drop;
#[cfg(test)] use task::failing;

pub trait Finally<T> {
fn finally(&self, dtor: ||) -> T;
fn finally(&mut self, dtor: ||) -> T;
}

impl<'a,T> Finally<T> for ||: 'a -> T {
fn finally(&self, dtor: ||) -> T {
try_finally(&mut (), (),
|_, _| (*self)(),
fn finally(&mut self, dtor: ||) -> T {
try_finally(&mut (), self,
|_, f| (*f)(),
|_| dtor())
}
}

impl<T> Finally<T> for fn() -> T {
fn finally(&self, dtor: ||) -> T {
fn finally(&mut self, dtor: ||) -> T {
try_finally(&mut (), (),
|_, _| (*self)(),
|_| dtor())
Expand Down

0 comments on commit b4ecbe9

Please sign in to comment.