ts-rust-bridge
ts-rust-bridge copied to clipboard
Support for HashMap?
Hi,
First of all, thank you for the great library! I am using this for a personal project. Any chance for supporting HashMap?
Best regards,
Hey @hoang17 I didn't have immediate need at the time and decided to defer adding new types until the need arrives.
It is possible that the time is now :)
There are two main questions how to approach this:
- What data structure will be used in JS?
- What kind of limitations/restrictions need to be in place?
They are kinda related to each, and here is my thoughts:
- I would love to avoid building custom types (like immutablejs or mobx-state-tree do).
- That leaves us either with native
Map
or plain object - Out of these I prefer native
Map
- which can potentially use any types for keys but in our use case it boils down to 'number' (f32, f64, i32) or
string
- at the time that restriction seemed to be major enough to defer the decision until I get more info.
I actually did a work around for one of my use cases: Have a collection of Vec(Tuple(Key, Value))
. In reality that is how serde internally transforms maps, of course, that incurs significant overhead on both sides to transform data to a 'Map' structure. For me it worked fine because there were not many values passed in.
@hoang17 pls let me know what are your thoughts and could you tell me more about your use case?
I think adding a HashMap
shouldn't be too hard, I probably can hack it within a day with the Key limited to numbers or strings.