holmesv3 / sicd-rs

Rust interface for SICD files
MIT License
2 stars 5 forks source link

Investigate implementing deserialize on SicdMeta #9

Open holmesv3 opened 11 months ago

Thomas-Oz-Dunn commented 8 months ago

standard serde?

holmesv3 commented 8 months ago

Sort of yes, the idea is that we may want to handle fields not being present or failing to parse properly without failing, while also not making them Option<T>. So, this was to look into how that would play out.

thomasjdunn commented 8 months ago

Thinking using something like #[serde(skip_serializing_if=field.is_empty)]

thomasjdunn commented 8 months ago

https://serde.rs/attr-skip-serializing.html

holmesv3 commented 8 months ago

Ideally I don't think they'd ever be empty unless it's already an optional field. The goal here is to work out Deserialize such that if a category like collection info fails, the program won't crash. Maybe there's a warning logged and it uses a Default value or something.

That skip serializing thing is neat, but also specific to Serialize, which is sort of the other end of the problem.

thomasjdunn commented 8 months ago

#[serde(default)] could then be used instead of Option<T>, just need to derive Default for every subclass

holmesv3 commented 8 months ago

That could work. I though default was only used if it wasn't present, not if there was an error parsing it. If that's the case great!

thomasjdunn commented 8 months ago

using Default might run into some sad manual work with enums, and yea we'll need to test the error catching