Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yea for sure, it’s a lot like swift being protocol oriented too. It’s a major paradigm shift I have to enforce in my head manually still at this point tho


Note that you can do Swift's protocol oriented programming / portocol extensions in Rust, too:

  trait Test {
      fn value(&self) -> i32;
  }

  impl dyn Test {
      fn multiplied(&self) -> i32 {
          self.value() * 2
      }
  }


What does `impl dyn` mean, exactly? That this only works for trait objects?


That it works for any type implementing the trait, via vtables. Otherwise, it’s a method specific to the particular type implementing the trait (a concrete implementation but distinct to the specific impl).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: