rust - 如何在 Rust 中定义递归类型别名?
问题描述
所以在 Rust 中,我可以像这样使用枚举定义递归类型:
enum Trie {
Child(HashMap<char, Box<Trie>>)
}
然而,考虑到这个枚举只有一个成员,这有点冗长。
我可以知道如何使它更简单吗?假设使用这样的类型别名?
// This code does not compile in rustc 1.55.0
type Trie = HashMap<char, Box<Trie>>;
解决方案
使用单个字段结构编译:
struct Trie(HashMap<char, Box<Trie>>);
推荐阅读
- linux - Linux Shell 脚本递归求幂
- python - 如何操作熊猫中的行块
- matlab - 维生素 D 浓度算法 - 基于公式的书写算法问题
- java - 访问arraylist的arraylist的arraylist的元素?
- javascript - 在jQuery中的单击事件上为变量赋值
- arrays - matlab如何格式化数组
- ubuntu - 无法在 Ubuntu 18.04 上安装 Rabbitmq-server
- javascript - 搜索/过滤嵌套数组 Javascript/Lodash
- php - 当第一个数字较小时,PHP <= 发生故障
- selenium - 从 Selenium Webdriver 中的弹出窗口中选择地址值