In the docs for the Send
trait, I see both
impl<T> Send for LinkedList<T>
where
T: Send,
and
impl<T: Send> Send for LinkedList<T>
What is the difference between these two syntaxes, and how would it impact my code if I was writing impl
declarations for my own trait?
Trait bounds defined inside a
where
clause are a superset of the trait bounds declared inline. The inline style existed before thewhere
clause; thewhere
clause was introduced in RFC 135:Since then you can also use higher-ranked trait bounds (
for <'a> ...
) in awhere
clause:If your needs can be met by the inline trait bounds, then there is no impact on your code. If you need the extra powers that only
where
enables, then you need to usewhere
.My personal style is to always use the
where
form. Having a single shape that is also easier togit diff
when adding new bounds is worth the extra line of code for me.