amazon-ion / ion-cli

Apache License 2.0
37 stars 15 forks source link

Create separate templates based on `AbstractDataType` for `struct.templ` #93

Open desaikd opened 8 months ago

desaikd commented 8 months ago

Currently struct.templ has if statements that help render a Rust struct based on AbstractDataType value. Instead generate different modules for ease of code maintenance and reviewer's readability.

desaikd commented 8 months ago

So, that is why I mentioned WriteAsIon in one of my other comments. WriteAsIon is already implemented for primitive types and for Vec<T: WriteAsIon>, and if we don't have an equivalent ReadFromIon or similar, then we need to create an issue for that in ion-rust.

On the other hand, I think there could also be reason to use wrapper if we want to add additional validation constraints, such as type::{ name: small_int, type: int, valid_values: range::[0, 9] }. In that case having struct SmallInt(u8) would actually allow us to add the range check to the type. That being said, I can't remember if we decided whether we want to ever have additional validations like that.

https://github.com/amazon-ion/ion-cli/pull/90#discussion_r1533061185