flutter_rust_bridge
flutter_rust_bridge copied to clipboard
Support for `HashMap<K, V>`
I am modelling complex data, some of which is best described with HashMap
s.
My app's architecture is as follows:
- There is a pure-Rust process
- There is a Flutter+Rust process
- There is a shared messaging model + core data model, which is run through flutter_rust_bridge and used to facilitate IPC
I have considered two alternatives:
- Create two separate core data models, one with
HashMap
s and one without, and translate between the two (this does not scale) - Use
Vec
throughout (this doesn't "feel" right, but it's what I'm going with for now)
Some thoughts about implementation:
To utilize existing infra, maybe we can convert HashMap<K,V>
to/from Vec<(K, V)>
and happily reuse the existing feature for Vec.
@Desdaemon What do you think?
Looking forward to your PR!
To utilize existing infra, maybe we can convert HashMap<K,V> to/from Vec<(K, V)> and happily reuse the existing feature for Vec.
The catch is that we haven't implemented anonymous tuple types yet -- a simpler way yet could be pushing both the keys and values in a vector then extract them pairwise, but there's room for new ideas.
The catch is that we haven't implemented anonymous tuple types yet
Aha you are right. Then what about this:
pub struct MyPair<K, V>(k: K, v: V);
Then Vec<MyPair<K,V>>
Looking forward to your PR!
I'm actually interested in the problem, especially after getting my feet wet elsewhere in the project, but I can't commit to attacking it right now. I have some pressing TODOs on my project and can use Vec
there for the time being.
I'll comment here if I'm able to take it on at some point.
I am very grateful for this project and I hope to contribute more in the future!
@SecondFlight Take your time and happy to see that this project helps you!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
👀
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
👀
👀
Feel free to PR!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.
Given interest in this issue (at https://github.com/fzyzcjy/flutter_rust_bridge/issues/954), this issue is unklocked :)
For future readers:
https://github.com/fzyzcjy/flutter_rust_bridge/issues/954#issue-1521895082 by @dbsxdbsx I currently met a situation needs to pass a struct with a field of
Vec<HashMap<String, String>>
, just like this: #329. I tried to work around it by making the type ofVec<Vec<(String,String)>>
, but then frb errors with :'parse_type failed for ty=Vec<Vec<(String,String)>>'
.I wonder:
- Is there some progress on this issue?
- Should rust type
HashMap
be supported to map intoMap
in Dart, or other type?- If this issue is intended to be solved by directly mapping rust
HashMap
into a kind ofMap
in Dart, what about other map in rust, likeBtreeMap
orSortedMap
-- say, doing the same as that onHashMap
?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.