我尝试了以下 Rust 类型别名:
type Name = String;
它运行得很好。所以我尝试了一个变体:
type Name = &str;
这个失败了:
error[E0106]: missing lifetime specifier
--> src/main.rs:1:17
|
1 | type Name = &str;
| ^ expected lifetime parameter
为什么类型别名需要生命周期参数?我该如何添加它?