mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 02:38:04 +02:00
nak,compiler: Move AttrList into NAK
AttrList never really made sense as part of AsSlice. The trait returns slices so it makes sense that it would return slice of attributes. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41410>
This commit is contained in:
parent
b0ccba02f7
commit
14fcd9b2f8
3 changed files with 25 additions and 26 deletions
|
|
@ -3,30 +3,13 @@
|
|||
|
||||
use std::ops::Deref;
|
||||
use std::ops::DerefMut;
|
||||
use std::ops::Index;
|
||||
|
||||
pub enum AttrList<T: 'static> {
|
||||
Array(&'static [T]),
|
||||
Uniform(T),
|
||||
}
|
||||
|
||||
impl<T: 'static> Index<usize> for AttrList<T> {
|
||||
type Output = T;
|
||||
|
||||
fn index(&self, idx: usize) -> &T {
|
||||
match self {
|
||||
AttrList::Array(arr) => &arr[idx],
|
||||
AttrList::Uniform(typ) => typ,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AsSlice<T> {
|
||||
type Attr;
|
||||
|
||||
fn as_slice(&self) -> &[T];
|
||||
fn as_mut_slice(&mut self) -> &mut [T];
|
||||
fn attrs(&self) -> AttrList<Self::Attr>;
|
||||
fn attrs(&self) -> &'static [Self::Attr];
|
||||
}
|
||||
|
||||
impl<T, A> AsSlice<T> for Box<A>
|
||||
|
|
@ -41,7 +24,7 @@ where
|
|||
fn as_mut_slice(&mut self) -> &mut [T] {
|
||||
self.deref_mut().as_mut_slice()
|
||||
}
|
||||
fn attrs(&self) -> AttrList<Self::Attr> {
|
||||
fn attrs(&self) -> &'static [Self::Attr] {
|
||||
self.deref().attrs()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,9 +142,9 @@ pub fn derive_as_slice(
|
|||
}
|
||||
}
|
||||
|
||||
fn attrs(&self) -> AttrList<Self::Attr> {
|
||||
fn attrs(&self) -> &'static [Self::Attr] {
|
||||
static ATTRS: [#attr_type; #count] = [#attrs];
|
||||
AttrList::Array(&ATTRS)
|
||||
&ATTRS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -161,8 +161,8 @@ pub fn derive_as_slice(
|
|||
&mut []
|
||||
}
|
||||
|
||||
fn attrs(&self) -> AttrList<Self::Attr> {
|
||||
AttrList::Uniform(#attr_type::DEFAULT)
|
||||
fn attrs(&self) -> &'static [Self::Attr] {
|
||||
&[]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -203,7 +203,7 @@ pub fn derive_as_slice(
|
|||
}
|
||||
}
|
||||
|
||||
fn attrs(&self) -> AttrList<Self::Attr> {
|
||||
fn attrs(&self) -> &'static [Self::Attr] {
|
||||
match self {
|
||||
#types_cases
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1345,6 +1345,22 @@ impl SrcType {
|
|||
}
|
||||
}
|
||||
|
||||
pub enum AttrList<T: 'static> {
|
||||
Array(&'static [T]),
|
||||
Uniform(T),
|
||||
}
|
||||
|
||||
impl<T: 'static> Index<usize> for AttrList<T> {
|
||||
type Output = T;
|
||||
|
||||
fn index(&self, idx: usize) -> &T {
|
||||
match self {
|
||||
AttrList::Array(arr) => &arr[idx],
|
||||
AttrList::Uniform(typ) => typ,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type SrcTypeList = AttrList<SrcType>;
|
||||
|
||||
pub trait SrcsAsSlice {
|
||||
|
|
@ -1371,7 +1387,7 @@ impl<T: AsSlice<Src, Attr = SrcType>> SrcsAsSlice for T {
|
|||
}
|
||||
|
||||
fn src_types(&self) -> SrcTypeList {
|
||||
self.attrs()
|
||||
AttrList::Array(self.attrs())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1436,7 +1452,7 @@ impl<T: AsSlice<Dst, Attr = DstType>> DstsAsSlice for T {
|
|||
}
|
||||
|
||||
fn dst_types(&self) -> DstTypeList {
|
||||
self.attrs()
|
||||
AttrList::Array(self.attrs())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue