I'm trying to understand ownership in Rust and faced a misunderstanding related to transfer ownership. Consider the following code:
fn main() {
let closure = || 32;
foo(closure);
foo(closure); //perfectly fine
}
fn foo<F>(f: F) -> u32
where
F: Fn() -> u32,
{
f()
}
I thought that the ownership should be transferred and the second call foo(closure)
should not be allowed.
Why does it work?