Reputation: 3300
So in Rust, I can define recursive type using enum like this:
enum Trie {
Child(HashMap<char, Box<Trie>>)
}
However this is a little bit verbose, considering that this enum has only one member.
May I know how to make it simpler? Let's say using type alias like this?
// This code does not compile in rustc 1.55.0
type Trie = HashMap<char, Box<Trie>>;
Upvotes: 2
Views: 628
Reputation: 980
Using a single field struct compiles:
struct Trie(HashMap<char, Box<Trie>>);
Upvotes: 4