compiler/rust: impl AsSlice for Box
Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com> Reviewed-by: Seán de Búrca <leftmostcat@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37315>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
// Copyright © 2024 Collabora, Ltd.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use std::ops::Deref;
|
||||
use std::ops::DerefMut;
|
||||
use std::ops::Index;
|
||||
|
||||
pub enum AttrList<T: 'static> {
|
||||
@@ -26,3 +28,20 @@ pub trait AsSlice<T> {
|
||||
fn as_mut_slice(&mut self) -> &mut [T];
|
||||
fn attrs(&self) -> AttrList<Self::Attr>;
|
||||
}
|
||||
|
||||
impl<T, A> AsSlice<T> for Box<A>
|
||||
where
|
||||
A: AsSlice<T>,
|
||||
{
|
||||
type Attr = A::Attr;
|
||||
|
||||
fn as_slice(&self) -> &[T] {
|
||||
self.deref().as_slice()
|
||||
}
|
||||
fn as_mut_slice(&mut self) -> &mut [T] {
|
||||
self.deref_mut().as_mut_slice()
|
||||
}
|
||||
fn attrs(&self) -> AttrList<Self::Attr> {
|
||||
self.deref().attrs()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user