What does the question mark mean in a type parameter bound?
我找到了
1 2 3 4 5 6 | pub trait BorrowMut<Borrowed>: Borrow<Borrowed> where Borrowed: ?Sized, { fn borrow_mut(&mut self) -> &mut Borrowed; } |
我咨询了:
- The Rust Programming Language?1书,
- The Rust Reference?2,还有
- 什么是"未实现大小调整"?意思?在堆栈溢出
上,但没有找到解释。请在回答中提供参考。
?1 尤其是请参阅第5.20节特征 sub>?2 和第6.1.9节特征 sub>
<铅>
这意味着特征是可选的。当前语法是DST语法RFC中引入的。
我知道对
在此特定示例中,我们可以实现
一个内置实现使用了该功能:
1 | impl< T > BorrowMut<[T]> for Vec< T > |
如Matthieu M 。添加:
This is a case of a widening bound; in general bounds impose more constraints, but in the case of
Sized it was decided that unless otherwise noted a genericT would be assumed to beSized . The way to note the opposite would be to mark it?Sized ("maybeSized ").