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

Paul Backus snarwin at gmail.com
Thu Sep 10 17:57:09 UTC 2020


On Thursday, 10 September 2020 at 14:57:11 UTC, Jacob Carlborg 
wrote:
> On 2020-09-08 06:53, mw wrote:
>> Hi,
>> 
>> I'm trying this example:
>> 
>> https://dlang.org/phobos/std_csv.html
>> 
>> ```
>> struct Layout
>> {
>>      string name;
>>      int value;
>>      double other;
>> 
>>      @csvIgnore
>>      Layout* parent;  // add extra pointer
>> }
>> 
>> auto records = text.csvReader!Layout(';');
>> ```
>> 
>> Right now, if we add this extra pointer, the compiler will 
>> error out:
>> 
>> https://run.dlang.io/is/EvU6Ee
>> 
>> /dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(223): 
>> Error: template std.conv.toImpl cannot deduce function from 
>> argument types !(Layout*)(string), candidates are:
>> ...
>> 
>> I think if we can add add uda (e.g. @csvIgnore) support in 
>> std.csv, it will make the library more flexible to use.
>
> How about a more general attribute in `core.attribute`, like 
> `@nonSerialized`? This could be used by third party 
> serialization libraries. Then it could also be used by druntime 
> and Phobos to ignore things that should not be serializable. 
> Like threads, processes and sockets.

Existing serialization libraries [1][2] already define their own 
attributes for this sort of thing. I don't think there's anything 
to be gained by attempting to force standardization here.

If Phobos and/or the D ecosystem does someday decide to 
standardize on a shared @ignore attribute, std.csv can be easily 
upgraded for compatibility by adding `alias csvIgnore = 
core.attribute.ignore`.

[1] https://code.dlang.org/packages/asdf
[2] https://vibed.org/api/vibe.data.serialization/


More information about the Digitalmars-d mailing list