In Non-Lexical Lifetimes: Introduction, Niko includes the following snippet:
fn get_default3<'m,K,V:Default>(map: &'m mut HashMap<K,V>,
key: K)
-> &'m mut V {
map.entry(key)
.or_insert_with(|| V::default())
}
What does the || V::default()
mean here?
It is a closure with zero arguments. This is a simplified example to show the basic syntax and usage (play):
This prints:
Another example from the documentation:
It's a zero-argument lambda function.