avoid `XDeclaredButNotUsed` when no field `isnot JsonVoid` (#87)

Move the type definitions for `Writer` and `Flavor` closer to their
usage to avoid verbose hints when they are never used in an invocation.
This commit is contained in:
Etan Kissling 2024-02-28 23:01:21 +01:00 committed by GitHub
parent c869dae884
commit 56c788bb25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 4 deletions

View File

@ -198,14 +198,13 @@ proc writeRecordValue*(w: var JsonWriter, value: auto)
mixin enumInstanceSerializedFields, writeObjectField
mixin flavorOmitsOptionalFields, shouldWriteObjectField
type
Writer = typeof w
Flavor = Writer.Flavor
type RecordType = type value
w.beginRecord RecordType
value.enumInstanceSerializedFields(fieldName, fieldValue):
when fieldValue isnot JsonVoid:
type
Writer = typeof w
Flavor = Writer.Flavor
when flavorOmitsOptionalFields(Flavor):
if shouldWriteObjectField(fieldValue):
writeObjectField(w, value, fieldName, fieldValue)