DEV Community

Discussion on: Getting started with Rust: Enum on steroids!

Collapse
 
evancarroll profile image
Evan Carroll • Edited
fn take_care_of_dog(kind: DogKind) {
  match kind {
    DogKind::Doggo => take_care_of_doggo(),
    DogKind::Doge => take_care_of_doge(),
    DogKind::Pupper => take_care_of_pupper(),
  }
}

Can as of new rust be written like this,

impl DogKind {
  fn take_care(&self) -> u8 {
    match self {
      Self::Doggo => take_care_of_doggo(),
      Self::Doge => take_care_of_doge(),
      Self::Pupper => take_care_of_pupper(),
    }
  }
}
Collapse
 
mnivoliez profile image
mnivoliez

True. The question is now is there any difference between the two code after compile. I'll check that layer :)

Collapse
 
pointyfluff profile image
PointyFluff

zero cost abstractions?