Hey folks,
I'm wondering why I need in some cases angle brackets for paths and in others not. See here. When I remove the angle brackets in line 6 at the slice I get an error but with no explaination.
Can anybody explain this?
Regards
keks
Hey folks,
I'm wondering why I need in some cases angle brackets for paths and in others not. See here. When I remove the angle brackets in line 6 at the slice I get an error but with no explaination.
Can anybody explain this?
Regards
keks
Array of T
implements Clone
if T
implements clone:
impl<T, const N: usize> Clone for [T; N]
where
T: Clone
There must be a similar implementation for slice, but I can't find it right now (I'm on the phone).
You have to use a qualified path for things that aren't identifiers or a handful of keywords.
Sidenote, [T]
is not Sized
and thus cannot implement Clone
. So test2
is not callable.
It's to avoid syntactic ambiguity. In expression position, [
would begin an array literal, so you need some sort of disambiguation to get a type. This is exactly the same reason as that of the turbofish.