Hacker News new | past | comments | ask | show | jobs | submit login

It is so simple it does not have a name. It is simply a double deref + borrow.

Since "deref" can be implemented differently for each type, you cannot know what it does in general, but in this case '*Vec<T>' turns it into a '[T]'.

If you compile in release mode, all of the following implementations of 'clone' will emit identical assembly:

    <[T]>::to_vec(&**self)

    <[T]>::to_vec(&self[..])

    <[T]>::to_vec(self.as_slice())

    self.as_slice().to_vec()
The stdlib picked the coolest looking one. Can't fault them for that.



Honestly I'd have preferred `.as_slice().to_vec()`




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: