小编ran*_*and的帖子

是否可以在Rust中使用多种类型进行模式匹配?

好像你不能.如果没有,是否有计划支持添加它或运行时类型信息(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 => {
            // ...
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这个例子很简单.在现实生活中,只有x多种类型才有用.例如let x = function_with_multiple_return_types();.

pattern-matching rust

3
推荐指数
1
解决办法
3076
查看次数

标签 统计

pattern-matching ×1

rust ×1