fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.29k stars 301 forks source link

support for IndexMap or custom encoder/decoder for generic types #2402

Open uditrugman opened 2 weeks ago

uditrugman commented 2 weeks ago

Is there a way to use custom Encoder/Decoder for IndexMap or in general to add custom encoder/decoder for Generic Types?

Thanks

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

fzyzcjy commented 1 week ago

Generics have not been supported yet. A quick method may be to define Rust macros, such that you can easily generate arbitrary generic types.

uditrugman commented 1 week ago

Is there a way to add custom encode/decode for a specific generic type?

for example IndexMap\<String, usize>

fzyzcjy commented 1 week ago

https://cjycode.com/flutter_rust_bridge/guides/types/translatable/custom

uditrugman commented 1 week ago

I tried that already but for some reason it ignores my encode/decode functions and generate a new dart type. is there an example of how to use Encode/Decode for a generic with specific type?

fzyzcjy commented 1 week ago

Hmm then looks like it is not implemented yet. A quick workaround is to use the newtype pattern, for example:

pub struct MyIndexMapStringUsize(IndexMap<String, usize>);

and then do custom encode/decode on it.

As usual, this can be done via a macro to avoid repeating the code.