Rollup merge of #65444 - spastorino:as-ref-for-list, r=Mark-Simulacrum

Implement AsRef<[T]> for List<T>

r? @Mark-Simulacrum
This commit is contained in:
Tyler Mandry 2019-10-15 16:08:00 -07:00 committed by GitHub
commit 3182f73e8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -701,6 +701,13 @@ impl<T> Deref for List<T> {
type Target = [T];
#[inline(always)]
fn deref(&self) -> &[T] {
self.as_ref()
}
}
impl<T> AsRef<[T]> for List<T> {
#[inline(always)]
fn as_ref(&self) -> &[T] {
unsafe {
slice::from_raw_parts(self.data.as_ptr(), self.len)
}