Why can a non-capturing closure be used after transferring ownership?

Viewed 79

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()
}

playground

I thought that the ownership should be transferred and the second call foo(closure) should not be allowed.

Why does it work?

1 Answers
Related