zig-toml icon indicating copy to clipboard operation
zig-toml copied to clipboard

Field Configuration in Serialization

Open AMythicDev opened this issue 1 year ago • 1 comments

As I am building the serializer, I think we need some sort of way to deal with formatting configuration for the individual fields like which fields need to be serialized as a top level table and which should be written as a inline table.

I am kinda unsure about how to go about this. We can use a StringHashMap where keys are the fully qualified paths and value will be a struct like FieldConfig which contains all the options that can be set for a field.

I am not sure about this one but we can also go with a anonymous tuple.

Would love to know your opinions on this

AMythicDev avatar Feb 01 '25 09:02 AMythicDev

Yeah, this is a great point. Here we can go arbitrary deep. Personally, I value simplicity and determinism over feature richness. I'd be totally fine if my structs are always serialized without inline tables at all and with keys with one level only, but... that all keys (fields and tables) are sorted.

But back to the original question: how to configure. I can imagine having a SerializationConfig like a HashMap<Path, FieldConfig>, where Path is like a toml multilevel key string, and FieldConfig can contain infos like Inline for tables, or depth_level for fields. So the usage would be populating that config HashMap with all possible hints that influence the cosmetics.

sam701 avatar Feb 01 '25 20:02 sam701