繁体   English   中英

如何确保特征范围内的特征边界?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM