flutter_rust_bridge icon indicating copy to clipboard operation
flutter_rust_bridge copied to clipboard

Support for `HashMap<K, V>`

Open SecondFlight opened this issue 2 years ago • 12 comments

I am modelling complex data, some of which is best described with HashMaps.

My app's architecture is as follows:

  1. There is a pure-Rust process
  2. There is a Flutter+Rust process
  3. 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:

  1. Create two separate core data models, one with HashMaps and one without, and translate between the two (this does not scale)
  2. Use Vec throughout (this doesn't "feel" right, but it's what I'm going with for now)

SecondFlight avatar Feb 11 '22 02:02 SecondFlight

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!

fzyzcjy avatar Feb 11 '22 02:02 fzyzcjy

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.

Desdaemon avatar Feb 11 '22 02:02 Desdaemon

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>>

fzyzcjy avatar Feb 11 '22 02:02 fzyzcjy

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 avatar Feb 11 '22 02:02 SecondFlight

@SecondFlight Take your time and happy to see that this project helps you!

fzyzcjy avatar Feb 11 '22 02:02 fzyzcjy

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.

stale[bot] avatar Apr 12 '22 04:04 stale[bot]

👀

fzyzcjy avatar Apr 12 '22 04:04 fzyzcjy

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.

stale[bot] avatar Jun 11 '22 06:06 stale[bot]

👀

SecondFlight avatar Jun 12 '22 12:06 SecondFlight

👀

TENX-S avatar Jul 17 '22 06:07 TENX-S

Feel free to PR!

fzyzcjy avatar Jul 17 '22 06:07 fzyzcjy

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.

stale[bot] avatar Sep 15 '22 11:09 stale[bot]

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.

github-actions[bot] avatar Oct 06 '22 13:10 github-actions[bot]

Given interest in this issue (at https://github.com/fzyzcjy/flutter_rust_bridge/issues/954), this issue is unklocked :)

fzyzcjy avatar Jan 06 '23 04:01 fzyzcjy

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 of Vec<Vec<(String,String)>>, but then frb errors with : 'parse_type failed for ty=Vec<Vec<(String,String)>>'.

I wonder:

  1. Is there some progress on this issue?
  2. Should rust type HashMap be supported to map into Map in Dart, or other type?
  3. If this issue is intended to be solved by directly mapping rust HashMap into a kind of Map in Dart, what about other map in rust, like BtreeMap or SortedMap-- say, doing the same as that on HashMap?

fzyzcjy avatar Jan 06 '23 04:01 fzyzcjy

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.

stale[bot] avatar Mar 08 '23 00:03 stale[bot]

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.

github-actions[bot] avatar Mar 29 '23 04:03 github-actions[bot]