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

  fn greet<T: Player>(&self, other: &T);
Yeah, this doesn't work, but the equivalent to what you are writing in Julia does:

  fn greet(&self, other: Box<dyn Player>);


I’m not sure what is meant here, because that top example would compile.

edit - Alright I think I see what the original article was trying to express. In the original article that top example method was defined as part of a trait. Because that method is generic that would make the trait not object safe. On its own that is fine (this would still compile), but there was some previous example code which relied on this trait being object safe.


Or even just pass by reference if you don't need to take the box:

    fn greet(&self, other: &dyn Player);




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

Search: