Comment

Comment by TakeBlaster16

    enum MyEnum { Ok(u8), NotOk }
    
    fn main() {
        let value = MyEnum::Ok(42);
        assert!(matches!(value, MyEnum::Ok(_)));
        
        match value {
            MyEnum::Ok(x) => assert_eq!(x, 42),
            MyEnum::NotOk => unreachable!(),
        }
    }
No unsafe to be found. The feature is there, it just has a different keyword than you might be used to -- the same way Haskell and Java both have something called "class" that mean different things.

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton