indexmap-rs/indexmap

Serializing

Closed this issue · 3 comments

I took a look at the related PR: #158
And found the serde_seq, but didn't see how to apply it outside of a struct.

I'm just trying to serialize an index map. The project is for helping me learn rust, so I don't have a ton of experience.
Using HashMap in place of IndexMap works, other than the fact that I need keys to be in order.

It looks from the PR that you have implmented Serialize, so I don't fully understand why rust is complaining about it not being implemented. Any suggestions for yaml serialization?

error[E0277]: the trait bound `IndexMap<&str, std::option::Option<serde_json::Value>>: Serialize` is not satisfied
   --> src/main.rs:107:39
    |
107 |         let s = serde_yaml::to_string(&version_info)?;
    |                                       ^^^^^^^^^^^^^ the trait `Serialize` is not implemented for `IndexMap<&str, std::option::Option<serde_json::Value>>`
    | 
   ::: /Users/jeffhykin/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_yaml-0.8.17/src/ser.rs:854:8
    |
854 |     T: ser::Serialize,
    |        -------------- required by this bound in `serde_yaml::to_string`

Nope, I'll try that. And if there's an enable-all-features option I'll probably switch to that as well. I'll post on here once I get back into the codebase

Thanks!

bluss commented

Thanks both. Using the required feature should be enough, feel free to open an issue if it doesn't work with that. 🙂