Noob: Syntax? - Let new_x = || { x::new() }?


What is the || in this syntax suggesting?

let new_set = || { Set::<Name>::new() };


That new_set will be a closure that doesn’t take any argument and with an inferred return type. Similar to a function fn() -> T { Set::<Name>::new() }, but with access to the local stack and where T is the return type of Set::<Name>::new(). You can read more about them in The Book.


The usage would then be

let new_set = || { Set::<Name>::new() };

let actual_value = new_set();
let value2 = new_set();


Yeah, I was wrong about not returning anything. The return type is from the block.


Just edit it, nobody will ever know.


What are you talking about? What am I talking about?!


Something about an edit… which nobody might spot, if they know to click on the pencil top tight of the post showing the diff and history. :open_mouth:


That pencil is purely decorative :wink:


It is an easter egg. If you watch it long enough it will transform into a golden coin which drops onto your desk.


Cool! I will keep this coin in a special place :smile: