In dynamic languages, like Clojure, it is easy to express collections with different types:
{:key1 "foo", :key2 [34 "bar" 4.5], "key3" {:key4 "foobar"}}
In Rust, I have seen the use of enums:
pub enum Value {
Null,
Bool(bool),
Number(f64),
String(String),
...
}
But different programmers will choose different enums to represent the same encapsulated type. There is also the Any
trait but it is experimental.
What is the idiomatic way in Rust to represent collections of items of different types? Some examples and/or links to implementations would be very nice.