libsyntax: use unboxed closures

This commit is contained in:
Jorge Aparicio
2014-12-08 13:28:32 -05:00
parent 2160427900
commit 0dac05dd62
32 changed files with 377 additions and 245 deletions

View File

@@ -56,12 +56,16 @@ pub fn P<T: 'static>(value: T) -> P<T> {
impl<T: 'static> P<T> {
/// Move out of the pointer.
/// Intended for chaining transformations not covered by `map`.
pub fn and_then<U>(self, f: |T| -> U) -> U {
pub fn and_then<U, F>(self, f: F) -> U where
F: FnOnce(T) -> U,
{
f(*self.ptr)
}
/// Transform the inner value, consuming `self` and producing a new `P<T>`.
pub fn map(mut self, f: |T| -> T) -> P<T> {
pub fn map<F>(mut self, f: F) -> P<T> where
F: FnOnce(T) -> T,
{
unsafe {
let p = &mut *self.ptr;
// FIXME(#5016) this shouldn't need to zero to be safe.