User Defined Attributes

Tove tove at fransson.se
Wed Nov 14 05:28:02 PST 2012


On Wednesday, 14 November 2012 at 13:03:18 UTC, David Nadlinger 
wrote:
> On Wednesday, 14 November 2012 at 11:18:28 UTC, Tove wrote:
>> There was the example with Thrift...
>>
>>  struct UserProfile {
>>        1: i32 uid,
>>        2: string name,
>>        3: string blurb
>>      }
>>      service UserStorage {
>>        void store(1: UserProfile user),
>>        UserProfile retrieve(1: i32 uid)
>>      }
>>
>> You could use a user defined type for the struct... but for 
>> the members it would make sense to use the native type 
>> directly... and if you traverse the annotation in sequence 
>> rather than as standalone entities.. it's perfectly safe to 
>> use 1,2,3 as annotation...
>
> But what if you want to use that struct with another library as 
> well, for which you might also want to tack some ids on the 
> fields? I'm the author of the current D implementation in 
> Thrift, and if/when user defined attributes become stable and 
> I'll amend it to take advantage of UDAs, I'll definitely not go 
> for raw literals…
>
> David

// in this nested scope, all uints are interpreted as belonging 
to the thrift module.
[std.attributes(uint, thrift)]
struct UserProfile
...

// error detected at compile-time
[std.attributes(uint, thrift), std.attributes(uint, thrift2)]
struct UserProfile
...



More information about the Digitalmars-d-announce mailing list