Stream: t-compiler/help

Topic: How to understand &**&Vec[T]?

Yan Luo (Aug 09 2019 at 03:36, on Zulip):

Hello, I am reading the Clone implementation for Vec[T] in In the implementation of the Clone trait for Vec[T], the "clone" fn is like:
fn clone(&self) -> Vec[T] {
In my understanding, self here is a reference. *self is still a reference to Vec[T], and **self is also a reference to Vec[T] because Deref for &T returns &T. Why are there 2 deref?


Nick12 (Aug 23 2019 at 02:03, on Zulip):

**self just dereferences self twice, once to go from &Vec to Vec, and once more, I assume to use the Deref impl to go to a [T]. Then it takes a ref, making it a slice, and calls slice::to_vec on it

Last update: Sep 18 2020 at 19:30UTC