请看以下代码:
struct Human {
name: String,
profession: Profession,
}
enum Profession {
Doctor,
Teacher
}
struct Family {
family_doctor: // How to express type that will mean Human (because name matters) of profession Doctor?
}
通过使Human
成为通用类型,并将变体Doctor
作为profession
字段的类型参数传递,是否可以实现这一点?如果不行,那么您建议的最接近这种关系的解决方法是什么?
请注意,这个问题可能看起来像是一个旧问题的重复。但首先,Rust在不断发展,其次,我正在寻找一种解决方法。