I don't know much about grammars, but would it be possible and desirable to parse || as an empty closure? To avoid confusion with the "or" operator, we could use a space like | |? Right now we have to do || { } for an empty closure which is tough to read. This would be convenient for example if a function takes a callback and we want to provide no callback.
@leodasvacas,
As for me || is harder to read as an empty closure.
I'd much rather have an stdlib function nop in scope and use that one. Some arbitrary symbol magic sounds like it makes for unreadable and easily breaking code.
Note that you can just declare nop in your own in fewer characters that it would take you to write a use to get it out of the stdlib. So I suggest you simply write fn nop() {} somewhere in your code.
use std::nop;
fn nop() {}
fn foo<F: Fn()>(_: F) {}
fn bar<F: FnMut()>(_: F) {}
fn bak<F: FnOnce()>(_: F) {}
fn main() {
foo(nop);
bar(nop);
bak(nop);
}
Why not just use {} to present the empty clousure? This is an anonymous code block anyway, and supposed to do nothing. And furthermore we could let the anonymous code block present any clousure that does not accept parameters.
Clearly we don't want this, thanks to those who gave feedback!
Most helpful comment
I'd much rather have an stdlib function
nopin scope and use that one. Some arbitrary symbol magic sounds like it makes for unreadable and easily breaking code.