devlog 23
🐇 Let’s turn to discussing the JSON output changes. We can add another option
to XvcOutputLine, like XvcOutputLine::Json(T: Serialize), that will output
the type using serde_json. It won’t introduce any other type.
🐢 Yes, but what will T be? Although store structures have Serde
implementations, they are not particularly useful for this.
🐇 We can have output types, named like XvcFileListOutput, that will be
converted to strings with serialization.
🦊 We do something similar in xvc pipeline export and import commands. We
use
XvcPipelineSchema
and XvcStepSchema just for the import and export commands. We’ll write similar
structs for all JSON output and will use Serde to convert these to strings.
🐢 Unlike the import and export commands, we have optional fields in the
output, though. I don’t want content digests to appear in JSON output if they
are not required.
🐇 Let’s search for optional fields in Serde.
🦊 There is a crate for optional fields.
🐢 We don’t need another crate for this. Serde has the
skip_serializing_if attribute
for fields. We can add Option::is_none as a method to these to skip outputting None
fields. All those fields, in this case, will be optional.
🐇 This is fine. We already use structs to format the xvc file list output. We
can just use them to output JSON.