• 0 Posts
  • 1 Comment
Joined 2 年前
cake
Cake day: 2024年3月5日

help-circle
  • It’s because they wanted to hack control flow functionality into expressions. Returning None is actually returning something, but never is just a placeholder for any type when they want to do things that may exit the expression entirely. This is an example in the docs

    let num: u32 = match get_a_number() {
        Some(num) => num,
        None => break,
    };
    

    Break exits the expression without ever producing a value.

    This is an unfortunate wart to appease a desire to those that want to be able to write code like they do in legacy languages. There should have been better ways to do this without being a hack IMO