On page 295 of Programming Rust you can find the following:
Fortunately, the standard library includes the blanket implementation:
impl<'a, T, U> AsRef<U> for &'a T where T: AsRef<U>, T: ?Sized, U: ?Sized, { fn as_ref(&self) -> &U { (*self).as_ref() } }
I'm confused at the use of &'a
there. What is the context of that? It's not being used in an argument of as_ref
nor tied to the output of &U
. I don't think I fully understand lifetimes when used in this context.
I looked this up because I still didn't understand it and the answers still weren't clicking (making sense). I found convert.rs
. This doesn't seem to have any lifetimes anywhere, but it implements the AsRef
trait. So why does the book have this, and not the actual code in Rust? Where can I find the "blanket implementation" mentioned in the book?