Beginner Rust
Q36 / 100

What is the Fn, FnMut, FnOnce trait hierarchy?

Correct! Well done.

Incorrect.

The correct answer is B) FnOnce consumes captured vars (called once); FnMut mutates them (called repeatedly); Fn only borrows (called any number of times)

B

Correct Answer

FnOnce consumes captured vars (called once); FnMut mutates them (called repeatedly); Fn only borrows (called any number of times)

Explanation

FnOnce ⊇ FnMut ⊇ Fn. A function accepting Fn can be passed any closure. Closures implement the most specific trait based on how they capture.

Progress
36/100