Skip to content

Instantly share code, notes, and snippets.

@NickyMeuleman
Created July 19, 2021 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickyMeuleman/c2f1d5ceb354bc8f4dc1f7d9f7ec9f29 to your computer and use it in GitHub Desktop.
Save NickyMeuleman/c2f1d5ceb354bc8f4dc1f7d9f7ec9f29 to your computer and use it in GitHub Desktop.
Rust enum impl block
#[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