看起来好像你不能这样做。如果不行,是否有计划支持它或者运行时类型信息(RTTI)?
struct Bus;
struct Car;
struct Person;
fn main() {
let x = Bus;
//or more realistically, let x = function_with_multiple_return_types();
match x {
Car => {
// ...
}
Bus => {
// this gets executed
}
Person => {
// ...
}
}
}
这个示例很简单。在实际应用中,只有当x
可以是多种类型时才有用。例如:let x = function_with_multiple_return_types();
。