The post included the following example along with a link to the code on the Rust Playground: Rust Playground
fn twice(x: int, f: |int| -> int) -> int {
f(x) + f(x)
}
fn square(x: int) -> int { x * x }
fn main() {
twice(5i, square); // evaluates to 50
}
But compiling the code gives an error:
<anon>:1:21: 1:22 error: expected type, found `|`
<anon>:1 fn twice(x: int, f: |int| -> int) -> int { f(x) + f(x) }
^
playpen: application terminated with error code 101
I assume that the example worked in the past and that the syntax has changed since it was posted. I'd be curious to know what the correct syntax is now.
A related question I had is what is the difference between Fn and fn? I see both are used in your post and I've seen both used in different contexts elsewhere, but I don't know exactly what the difference between the two is.