title: Early-breaking from Rust's match
body: <p>I want to switch through many possible cases for <code>x</code> and there's one case (here <code>x == 0</code>) where I want to check the result of some additional code to determine what to do next. One possibility is to return early from the match.</p>
  <p>I'd use <code>break</code> to do this early-returning in C, but this isn't allowed in Rust. <code>return</code> returns from the parent function (in this case <code>main()</code>) and not from the match only (i.e. the <code>println!</code> at the end isn't run!).</p>
  <p>I could just negate the sub-condition (here <code>y == 0</code>) and indent the whole lot of following code -- but I find this ugly and unreadable.</p>
  <p>Putting the sub-condition into a match-guard is no option for me since it's simply too big.</p>
  <p>Is this possible in Rust or is there a better alternative (except creating another subfunction or other work-arounds)?</p>
  <p>Minimal example:</p>
  <pre><code>fn main() {
      let x = 1;
  
      match x {
          1 =&gt; {
              let y = 0;
              /*
               * do ev1l stuff to y that I don't want to put into the match-guard
               * as it's simply too much.
               */
  
              /* break early ... */
              if y == 0 {break;} // &gt; error: `break` outside of loop [E0268]
  
              assert!(y != 0, &quot;y was 0!&quot;);
              /* do other stuff in here. */
          }
          _ =&gt; {}
      }
  
      println!(&quot;done matching&quot;);
  }
  </code></pre>
  <p>I found <a href="http://blog.rust-lang.org/2015/04/17/Enums-match-mutation-and-moves.html" rel="nofollow noreferrer">Mixing matching, mutation, and moves in Rust</a> — is it wrong?</p>
  <blockquote>
  <p><code>match</code> embraces both imperative and functional styles of programming: you can continue using <code>break</code> statements, assignments, et cetera, rather than being forced to adopt an expression-oriented mindset.</p>
  </blockquote>