pub struct Entity {
name: String,
}
fn walk<T>(entity: T) {
eprintln!("{} walked", entity.name);
}
Currently the following code doesn't compile, because the type T doesn't have a name
field.
I know there are trait bounds in rust, is there some "field bound"?
Do i really have to:
trait HasName {}
impl HasName for Entity {}
fn walk<T: HasName>(entity: T) {
eprintln!("{}", entity.name);
}
Oh wait, that too won't compile!
Here's a working example
I mean, there's got to be something simpler than that.
Maybe some kind of struct destructuring like in javascript?