What are the possible operators for traits in a where clause in Rust?

。_饼干妹妹 提交于 2019-12-24 09:28:19

问题


I'm learning Rust and got to the chapter on trait bounds. In that chapter, they give an example with the + (plus) operator to enumerate all required traits in a where clause.

What other operators are allowed on traits in Rust? I searched but I wasn't able to find any documentation about this. Does Rust support 'or' notation, brackets, negation?


回答1:


'or' notation

No. Such a thing doesn't make sense to me — what would the code do if something could be A OR B?

brackets

No, unless you count the parenthesis in Fn(...) and friends, the use of angle brackets as generics (Vec<T>) or the use of square brackets in slices ([u8]), but these are parts of types.

Again, such a request doesn't make sense to me, why would you need any kind of grouping?

negation

No. I believe this is due to the fact that handling negative logic makes things a lot more complicated.

other operators

There's the ? (question mark) bound.


Source: I've written a parser of Rust code. While it's possible I've missed something, it parses all the ~37500 Rust files I've thrown at it, so it's a pretty good fit.



来源:https://stackoverflow.com/questions/46779310/what-are-the-possible-operators-for-traits-in-a-where-clause-in-rust

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!