add uda (e.g. @csvIgnore) support in std.csv?

Sebastiaan Koppe mail at skoppe.eu
Sat Oct 10 06:38:03 UTC 2020


On Thursday, 10 September 2020 at 19:11:03 UTC, Steven 
Schveighoffer wrote:
> To add to this, I have code that serializes the same types for 
> both vibe.d JSON for REST interfaces, AND to a database. In one 
> case, I want certain fields to be ignored (e.g. no reason to 
> send internal database ids to the browser), and in another case 
> I want other fields to be ignored.
>
> I'd rather have libraries define their own UDAs, and not expect 
> Phobos to design a UDA system that pleases all parties.
>
> -Steve

I have sometimes used a dedicated struct just to let the 
serialiser know how to deal with the fields. It would mostly be a 
copy of the original struct but with some udas here and there. It 
allows me to have different shapes even when targeting the same 
format.

Wrt to csv, you could serialise into an intermediate struct 
first, and from that into your target struct. It wouldn't be hard 
to convert struct a { string timestamp, name; double value; } 
into struct ab { Datetime timestamp; string name; double value; }


More information about the Digitalmars-d mailing list