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

This commit is contained in:
Santiago Pastorino 2019-10-15 12:55:39 -03:00
parent e413dc36a8
commit fa3a4aeae5
No known key found for this signature in database
GPG key ID: 88C941CDA1D46432

View file

@ -700,6 +700,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)
}