< 返回版块

WingDust 发表于 2022-01-02 21:06

let current_column = 1;
let max_column = 7;
edge = match current_column {
    0                    => Edge::Left,
    a if a == max_column => Edge::Right,
    _                    => Edge::NotAnEdge
};

上面的代码来自Why is this match pattern unreachable when using non-literal patterns?

这里为什么能将if 写入到 match 的 列举参数中

评论区

写评论
苦瓜小仔 2022-01-02 22:05

https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html#extra-conditionals-with-match-guards

1 共 1 条评论, 1 页