3 ms·
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 Pla
by richardwhiuk 6y ago
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>);
- JoshMcguigan 6y agoI’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.
- kevincox 6y agoOr even just pass by reference if you don't need to take the box: fn greet(&self, other: &dyn Player);