oknozor / musicbrainz_rs

A wrapper around the musicbrainz API
MIT License
38 stars 18 forks source link

Use Default::default instead of optionals everywhere #59

Closed oknozor closed 3 years ago

oknozor commented 3 years ago

Search, browse and fetch routes, entities are often inconsistent and we have to use Option almost every where to avoid de-serialization panic.

I am not a 100% sure this is the right approach but an alternative would be to have a Default implementation on every entities and use #[serde(default)] (on the struct not its fields) to avoid optional everywhere.

One possible downside is that we will have default values instead of json null. For instance using default on a missing string fields would produce "" instead off null -> None. This probably make it a little bit tedious to consume query results for end users since they will need to check for empty strings instead of Option.

On the other hand this is really convenient to populate vecs from empty or missing json arrays.

Maybe we should use both the default implementation and carefully chose which field should be Option.