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:
Mel Henning
2025-09-10 21:47:24 -04:00
committed by Marge Bot
parent 74696758a2
commit 611c5ebce5
+19
View File
@@ -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()
}
}