To Deref or not to Deref?

76 points awesomealchemy 50 comments

Do you impl Deref for your "newtypes" or do you stick with the .0 syntax?

struct Frequency(f32);
impl Deref for Frequency {
  type Target = f32;
  fn deref(&self) -> &Self::Target {
    &self.0
  }
}

I'm torn. The .0 syntax gives me C++ std::pair PTSD and hurts my eyes. BUT the deref adds boilerplate and we still need to deref it...