相关疑难解决方法(0)

为什么带有保护子句的匹配模式不详尽?

考虑以下代码示例(playground)。

#[derive(PartialEq, Clone, Debug)]
enum State {
    Initial,
    One,
    Two,
}

enum Event {
    ButtonOne,
    ButtonTwo,
}

struct StateMachine {
    state: State,
}

impl StateMachine {
    fn new() -> StateMachine {
        StateMachine {
            state: State::Initial,
        }
    }

    fn advance_for_event(&mut self, event: Event) {
        // grab a local copy of the current state
        let start_state = self.state.clone();

        // determine the next state required
        let end_state = match (start_state, event) {
            // starting with initial
            (State::Initial, Event::ButtonOne) => State::One,
            (State::Initial, …
Run Code Online (Sandbox Code Playgroud)

pattern-matching rust

5
推荐指数
1
解决办法
1597
查看次数

标签 统计

pattern-matching ×1

rust ×1