[英]How to ensure trait bounds within a trait?
如果我有类似以下Foo
特征的特征
trait Foo: Bar {
type Account: SomeTrait;
}
有一个需要Bar
的 trait bound
trait Bar {
type UserId;
}
如何在Foo
特征中请求此特征需要Bar
特征中的UserId
类型为u32
?
重要提示:我无法编辑Bar
特征。
这可以指定为命名的通用参数: Bar<UserId=u32>
。
trait SomeTrait {}
trait Foo: Bar<UserId=u32> {
type Account: SomeTrait;
}
trait Bar {
type UserId;
}
见操场。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.