在this issue page for Rust,它为core::num::bignum::FullOps
提供了以下示例代码:
pub trait FullOps {
...
fn full_mul(self, other: Self, carry: Self) -> (Self /*carry*/, Self);
...
}
然后它说:
这里函数
full_mul
只返回一个(Self, Self)
元组 当Self
- 类型为Sized
时格式良好 - 由于这个原因和其他原因, 只有当Self
为Sized
时,这种特质才有意义。这个解决方案 案例和大多数其他案例是添加缺少的Sized
supertrait。
如何添加缺少的Sized
超级链接?
答案 0 :(得分:4)
“超级特质”只是一个限制,真的。
您可以在特征级别或方法级别放置绑定。在这里,建议您将其置于特质级别:
pub trait FullOps: Sized {
fn full_mul(self, other: Self, carry: Self) -> (Self, Self);
}
另一种解决方案是将其置于方法级别:
pub trait FullOps {
fn full_mul(self, other: Self, carry: Self) -> (Self, Self)
where Self: Sized;
}
答案 1 :(得分:2)