Created
May 22, 2023 20:18
-
-
Save matthewjberger/5a5ced920d4018cb0643550e75627b3d to your computer and use it in GitHub Desktop.
Rust Enum Comparison examples - Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e5ce29270cf49ee8bca9c3dc120b58fc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug, PartialEq, Eq)] | |
enum MyEnum { | |
Variant1(i32), | |
Variant2(String), | |
} | |
fn main() { | |
let a = MyEnum::Variant1(5); | |
let b = MyEnum::Variant1(5); | |
assert_eq!(a.eq(&b), true); | |
let c = MyEnum::Variant1(10); | |
assert_eq!(a.eq(&c), false); | |
let d = MyEnum::Variant2("Hello".into()); | |
let e = MyEnum::Variant2("Hello".into()); | |
assert_eq!(d.eq(&e), true); | |
let f = MyEnum::Variant2("World".into()); | |
assert_eq!(d.eq(&f), false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment