You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mostly I try to have the Rust library code with Rust types to let Rustler do the conversion. I have to use Term when the values could be any elixir term, which is probably what it is meant for.
I was wondering why Elixir would have Strings or Symbols as keys but Symbols are not supported as keys in the HashMap in Rust. Values seem to be fine if they are specified as Atoms.
the trait bound `rustler::Atom: Hash` is not satisfied
the trait `Decoder<'_>` is implemented for `HashMap<K, V>`
required for `HashMap<rustler::Atom, rustler::Term<'_>>` to implement `Decoder<'_>`
Maybe the keys should never be symbols in Rust, but if this is the case then was looking at the best way to convert. When using Term I can't find an easy way to get an item from the HashMap if wanting to do a string lookup. The best so far is to iterate through the items and convert all symbol keys to strings.
Would symbols as map keys be supported or is there a recommended approach for converting or looking up this type?
The text was updated successfully, but these errors were encountered:
@samfrench I've put together a quick PR ( #694 ) which should fix the issue you're having. The error message you were getting was because Atom didn't implement Hash, so it couldn't be used as a key in a HashMap.
@scrogson thank you for that. I'll keep an eye on it. I did see #474 the other day which looks related. There was discussion on it for reasons why it might be more complex. Maybe that is different and it was from a few years ago.
When I pass a Map to Rust it is fine if the keys are Strings or even if the keys and values are Terms.
Mostly I try to have the Rust library code with Rust types to let Rustler do the conversion. I have to use Term when the values could be any elixir term, which is probably what it is meant for.
I was wondering why Elixir would have Strings or Symbols as keys but Symbols are not supported as keys in the HashMap in Rust. Values seem to be fine if they are specified as Atoms.
Produces this:
Maybe the keys should never be symbols in Rust, but if this is the case then was looking at the best way to convert. When using Term I can't find an easy way to get an item from the HashMap if wanting to do a string lookup. The best so far is to iterate through the items and convert all symbol keys to strings.
Would symbols as map keys be supported or is there a recommended approach for converting or looking up this type?
The text was updated successfully, but these errors were encountered: