First, about joining the keys unordered. I found a few similar topics (like this one, which is for &str
keys though) and the simplest solution I could come up with was this:
let s = my_hash_map.keys().map(|n| n.to_string()).collect::<Vec<_>>().join(",");
Is there a simpler way to do it?
Also, I would often prefer the elements in the resulting string to be sorted, but from what I've seen the standard library still doesn't provide a sorted()
method I could simply plug into the above chain (as we normally would in Python, for example). So is there some other standard (with no external crates) simple way we could do that in a one-liner in Rust?