Attributes on Enum Members: Call for use cases.

Jacob Carlborg doob at me.com
Wed Nov 29 16:16:27 UTC 2017


On 2017-11-29 13:53, Seb wrote:

> UDAs for function arguments would be really awesome to have. Just 
> imagine how nice the Vibe.d web routes would look like:
> 
> auto postUser(@body User user, @errors Errors errors)
> 
> Instead of:
> @body("user")
> @errorDisplay
> auto postUsers(User _user, string  _error)
> 
> 
> 
> Or:
> 
> @path("/users/:id")
> auto getUser(@urlParam string id, @queryParam int page, @auth User user)
> 
> Instead of:
> 
> @path("/users/:id")
> @queryParam("page")
> @before!authenticate("user")
> auto getUsers(string _id, int page, User user)
> 
> 
> (This is pseudo-syntax as I write this from my phone).

Yeah, that would be nice. I had another use case in mind as well, for 
DStep. Clang supports nullability attributes [1] which could be 
translated to UDAs. They would do anything but would be more for 
documentation purpose. I guess external tools could be built to actually 
do something useful with the attributes. Example:

In C:

int fetch(int * _Nonnull ptr);

In D:

int fetch(@Nonnull int* ptr);


[1] 
https://clang.llvm.org/docs/AttributeReference.html#nullability-attributes

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list