`namedarg`: compiler plugin for named/labeled arguments, like Swift


[edit: ough, Discourse shouldn’t force capitalize the first character of thread titles…]

I wrote a thing:

An experimental (probably broken) procedural macro. Instead of code like this:

parser.parse_item(vec![], true, false)

this macro lets you write code like this!

parser.parse_item(attrs: vec![], macros_allowed: true, attributes_allowed: false)

Written partly as a proof of concept for a potential future Rust feature, but
also to be practical and usable today. Sort of. In theory.

Feedback highly desired, e.g. on topics ranging from “how do I use this” to “this is broken” to “why why why would you do this”.


It’s a nice experiment. But I’d like a simpler and less engineered semantics (like Ada language?). And perhaps it’s worth changing the syntax for type ascription (to what?) to avoid the syntax collision. But I am still not sure if Rust needs named arguments. I think adding the syntax as gated is a way to test it and understand if it’s good or bad.

On the other hand I think optional arguments and variadic generics (ad in D language, with “type level tuples” and their slicing and static foreach loops) are useful in Rust to improve APIs.