std: Deprecate finally
module
No in-tree users. Ugly interface. Closes #14332.
This commit is contained in:
parent
3a44a19af2
commit
e46620af45
@ -32,7 +32,7 @@
|
||||
//! # }
|
||||
//! ```
|
||||
|
||||
#![unstable]
|
||||
#![deprecated = "this was an unsightly interface. just implement Drop"]
|
||||
|
||||
use ops::{Drop, FnMut, FnOnce};
|
||||
|
||||
|
@ -12,11 +12,47 @@
|
||||
// ignore-windows FIXME #13259
|
||||
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(unsafe_destructor)]
|
||||
|
||||
use std::os;
|
||||
use std::io::process::Command;
|
||||
use std::finally::Finally;
|
||||
use std::str;
|
||||
use std::ops::{Drop, FnMut, FnOnce};
|
||||
|
||||
pub trait Finally<T> {
|
||||
fn finally<F>(&mut self, dtor: F) -> T where F: FnMut();
|
||||
}
|
||||
|
||||
impl<T, F> Finally<T> for F where F: FnMut() -> T {
|
||||
fn finally<G>(&mut self, mut dtor: G) -> T where G: FnMut() {
|
||||
try_finally(&mut (), self, |_, f| (*f)(), |_| dtor())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_finally<T, U, R, F, G>(mutate: &mut T, drop: U, try_fn: F, finally_fn: G) -> R where
|
||||
F: FnOnce(&mut T, U) -> R,
|
||||
G: FnMut(&mut T),
|
||||
{
|
||||
let f = Finallyalizer {
|
||||
mutate: mutate,
|
||||
dtor: finally_fn,
|
||||
};
|
||||
try_fn(&mut *f.mutate, drop)
|
||||
}
|
||||
|
||||
struct Finallyalizer<'a, A:'a, F> where F: FnMut(&mut A) {
|
||||
mutate: &'a mut A,
|
||||
dtor: F,
|
||||
}
|
||||
|
||||
#[unsafe_destructor]
|
||||
impl<'a, A, F> Drop for Finallyalizer<'a, A, F> where F: FnMut(&mut A) {
|
||||
#[inline]
|
||||
fn drop(&mut self) {
|
||||
(self.dtor)(self.mutate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[inline(never)]
|
||||
fn foo() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user