top | item 39598165

(no title)

wrcwill | 2 years ago

yeah, is there a way to deserialize using (val, err) instead of *val when the field is optional?

discuss

order

klabb3|2 years ago

Hmm, are we talking json parsing? Yes, the field would take the zero value. If you need to differentiate between the zero-value (eg empty string, 0 for numbers) you’d typically use a pointer only for that purpose. That kinda sucks but there are some good arguments for zero-defaults too.

The unmarshal functions take a reference but they don’t need to be declared as (heap-based) pointers. You can pass a `&val` directly. It needs a reference passed in to determine the type.

throw-the-towel|2 years ago

Just for curiosity's sake, what good arguments for zero-defaults exist?

wrcwill|2 years ago

yeah i meant if each field could be a tuple of (val, bool) or (val, err) to get around the pointer issue