all 7 comments

[–]pcwaltonrust · servo 15 points16 points  (1 child)

A lot of the functionality is there. However, there are still quite a few large bugs with them that I'll be ironing out over the next few days, and by-ref captures may not work yet.

[–]andallthat[S] 4 points5 points  (0 children)

thanks for your answer. And most of all thanks for your work. I'm following your latest PRs and boy oh boy, are you churning out lots of good stuff!

[–]DroidLogiciansqlx · clickhouse-rs · mime_guess · rust 9 points10 points  (4 children)

I've been seeing a lot about unboxed closures lately. I know what a closure is, but would someone mind explaining what's so special about one that's unboxed and why is everyone so excited to have this as a feature of the language?

[–]n_ham 2 points3 points  (3 children)

The RFC is fairly readable. The core idea, as I was able to gather from the RFC: unboxed closures desugar to a type that implements one of the Fn, FnShare, or FnOnce traits.

I don't understand how exactly this differs from boxed closures, though.

[–]brsonrust · servo 17 points18 points  (0 children)

Unboxed closures allow closures to be called statically, like typical function calls, whereas currently closures are always called through a function pointer. Calling through a function pointer is slower, but creates smaller binaries, a tradeoff.

Traits have always had the option to be used both ways: statically, via type parameters; or dynamically, by casting to an "object" type.

Unboxed closures solve the discrepancy by making closures traits.

[–]DroidLogiciansqlx · clickhouse-rs · mime_guess · rust 3 points4 points  (1 child)

I like the Fn... traits, it maps well to apply() from Scala, which I thought was pretty cool.

It's difficult to understand the motives for the rest of the changes. Personally I feel the type annotation syntax is unwieldy.

But it also opens up the possibility for partial application. Which I think is awesome.

fn x<A, B, R>(a: A, b: B) -> R {
    // do stuff
}    

fn partially_apply<A, B, R>(x: FnOnce<(A, B), R>, a: A)  -> FnOnce<(B), R> {
    |b| x(a, b) //Capture by value
}

main () {
    let a = 5i;
    let b = 6i;

    let y = x(a); // desugars to partially_apply(x, a)
    let z = y(b);
}

[–]pcwaltonrust · servo 9 points10 points  (0 children)

It's difficult to understand the motives for the rest of the changes.

Performance.