oxidecomputer / typify

compiler from JSON Schema into idiomatic Rust types
Apache License 2.0
423 stars 58 forks source link

Add option to generate code with `IndexMap` instead of `HashMap` #555

Open jon-zu opened 6 months ago

jon-zu commented 6 months ago

Sometimes It's required to preserve the order, If we could add a flag to generate code with IndexMap instead of HashMap . We could also just utilize serde_json::Map so It'd respect the serde_json feature flag.

ahl commented 6 months ago

Perhaps a generic "specify Map type" kind of setting? Some folks would prefer BTreeMap to HashMap so it might be nice to just allow this to be specified generically. I suppose we could do this for arrays and sets as well.

jon-zu commented 5 months ago

A special map type via settings is also a good choice, however It's somewhat convenient (can be also confusing ofc) that serde_json::Map is controlled over the feature flag in the Cargo.toml. So maybe allowing 3 options(Default, serde_json or custom) would be a decent setting. I can try to get a cli option working for this next week and make a pull request.

ahl commented 5 months ago

I'd welcome a pull request here. My suggestion is to provide an option for all modes (builder, macro, CLI) that lets you specify the fully qualified path of the map type you'd like. The assumption would be that it would be a type of the form T<K,V> that supports typical map-like operations (it would be nice in the docs if we specify what those map-like operations are specifically).