Created
July 19, 2021 14:31
-
-
Save NickyMeuleman/c2f1d5ceb354bc8f4dc1f7d9f7ec9f29 to your computer and use it in GitHub Desktop.
Rust enum impl block
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)] | |
pub enum Bucket { | |
One, | |
Two, | |
} | |
impl Bucket { | |
fn other(&self) -> Self { | |
match self { | |
Bucket::One => Bucket::Two, | |
Bucket::Two => Bucket::One, | |
} | |
} | |
} | |
fn main() { | |
dbg!(Bucket::One.other(), Bucket::Two.other()); | |
// Bucket::One.other() = Two | |
// Bucket::Two.other() = One | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment